Trouble using a loop to add characters to an array of "strings" in c? -


so tried both datatype char , data type int. nomatter printf shows first letter of inputted word. example if inputs dog 'd'. guess maybe syntax of word[i] takes first letter im not sure how fix that. know how fix this?

    #include <stdio.h>     #include <stdlib.h>     #include <string.h>     #include <time.h>     #define pause system("pause")     #define cls system("cls")   void getuserwords(int *counter, int words[]){             int i;              printf("how many words enter cross word puzzle\n");             scanf("%i",&*counter);             for(i=0; < *counter; i++){                 printf("please enter word #%i\n",i+1);                 scanf("%s",&words[i]);                 printf("the word %c added crossword puzzle\n",words[i]);                 pause;                 cls;             }//end              printf("your words have been added crossword puzzle");             cls;         }//end getuserwords 

if read c library documentation relating printf() , friends, remember "%c" format string single characters. if want print string terminating null, should use "%s".

you have:

 printf("the word %c added crossword puzzle\n",words[i]); 

but should have

 printf("the word %s added crossword puzzle\n",words[i]); 

also, make sure second arg function has enough space allocated store counter words.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -