I'm new to C so some clarification would be very helpful! I'm trying to use a scanner to ask my program for a series of words which I will store..what I have so far is,
char[]listOfWords[9999]; //creates a large array of characters
scanf("%s", listOfWords); //stores inputs into listOfWords
with this, I can access the first word easily, but it comes to a matter of accessing the second, and third words..any suggestion? For example, how my input was
Hello how are you guys
I can access "Hello" no problem, but how would I call "how" and "are"
char[]listOfWords[9999];won't compile. As for the problem,%sreads until it finds a whitespace character. You can call thescanfagain and again to read each word. Or simply usescanf("%[^\n]", listOfWords);to read in the whole line. Note that the previous approach will fail if the first character to be read by it is a\nand also, it will leave a newline character in thestdin. Another approach would be to usefgets(listOfWords, sizeof(listOfWords), stdin);. Note thatfgetsconsumes the newline character and stores it inlistOfWords.char[]listOfWords[9999];......definitely not C...listOfWords, you need to usestrtokwith space as the delimiter to get each word. Then, usestrlento find the length of each word.