Well, that makes sense, look at how your loops are nested:
- while we're still reading words into 'str'
- - loop over j 100 times
- - - loop over each letter in str, skip the punctuation and print each letter
Again - take a simple example (change the "100" to a "5", pick a simple input), work through the code step by step and think about what it's doing. Here's the execution path for input of "one two three":
- while loop reads "one" into str
- j = 0, set a[0] to "one", 1 letter at a time in inner loop; print it out
- j = 1, set a[1] to "one", 1 letter at a time in inner loop; print it out
- j = 2, set a[2] to "one", 1 letter at a time in inner loop; print it out
...etc till j = 100
- while loop reads "two" into str
- j = 0, set a[0] to "two", 1 letter at a time in inner loop; print it out
- j = 1, set a[1] to "two", 1 letter at a time in inner loop; print it out
...etc
You can see that isn't what you want to do. The problem here is with how your loops are organized - every time you read in one string with the scanf call, you're looping 100 times to fill in every character array in 'a' with the string you just read. What you
want to do is just fill in
one of the slots in 'a' with the string you just read. But which slot do you put it in? I guess that depends on how many strings you've read so far... *hint hint!*
Also, quick tip:
Code:
36. for(j = 0; j < 100; j++){
37. for(i = 0; i < 40; i++){
38.
39. printf("%c", a[j][i]);
40. }
41. }
This is a spot where you can take advantage of your character arrays - rather than printing each character individually, you can print out entire character arrays at once by doing this instead:
Code:
36. for(j = 0; j < 100; j++){
37. printf("%s\n", a[j] );
38. }
This is where what I said in that last post comes into play - a[j] resolves to a character array, so you can print it out with %s which is designed to use character arrays.
Also, if you're tired, note that programming when tired is extremely difficult. Sleep is advised. I myself am heading to bed, I'll check in on this thread at work tomorrow, hopefully some other people in this forum can help out too.