C program | SoloLearn: Learn to code for FREE!

0

C program

Can i have some help here please I have set of string elements assume it orange , cucumber,apple,kiwi how can i do c programming that take from user any set of the strings like that and assign every element of this set to index of array in ascending order ( first input by user first be indexed in array ) thanks for advance!

6/3/2020 12:29:07 PM

ebrahem hesham

11 Answers

New Answer

+2

I don't know if I've understand well the question but I'll try... First you must create an array of strings. Arrays are inmutable so you must set the number of elements and the length of each one: char arr[5][11]; // it can store 5 strings with 10 chars each (+end char); Then you can use a 'for' loop for enter each element p. eg. using scanf in each iteration: scanf("%s", arr[i]); Finally ask for a number and print the element. Remember that elements start at index 0 so you must subtract 1: printf("Your color is %d\n", arr[num-1]); --- The result could be something like this: https://drive.google.com/file/d/1N1YdTV61DysN4sMVfWY0Wg6WjnTK_eYQ/view?usp=drivesdk

+2

you can use a pointer to a pointer, pointer to an array or a 2d array then sort it in which ever order you want

+1

devanille thanks 😊 i really from my heart appreciate your help thanks again ❤️❤️❤️

+1

I have not understood your question properly give a explanation of input and output formate

+1

ebrahem hesham here is your answer i tried in cpp u can make in c . i hope u expect same output which i made. #include <iostream> using namespace std; int main() { const char *colour[4] = { "Autumn", "Winter", "Summer", "Yellow" }; for(int i=0;i<3;i++) { cout << colour[i] <<"-"<<i<<"\n"; } return 0; }

0

ebrahem hesham So what's the problem in this?

0

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 how can I do that ? The program i wanna do should solve two things the string that entered should be in punch of chars not only char and the second is to determine index to each element of this set strings

0

ebrahem hesham Attach your attempt here

0

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 what i attempt to do is when you enter the index of the string you get one of these elements defined in array which will retrieve the string name element belongs to that index like that Enter number to see : 3 Your color is "blue"

0

C,Cpp,Java,Html. How can I have set of strings ordered by index in an array in c instead of having characters only in indexing Input Spring , Autumn,winter, summer Output : Enter the seoson you need 2 Result The seoson is summer .

0

C,Cpp,Java,Html. Thanks 😘