i want to print all the rows of my array and for whatever reason im having some difficulty, probably a quick fix but i cant find it
Code:#include <stdio.h> #define length 1024 int Capitalize(int ch); void UserInput(char string[]); char NEW_2D_array(char* str); /* the main function prints a message to the user, the user inputs a string ** other functions are called to make sure that the desired information is found ** and ultimately printed neatly in a table like this... ** Total Words: 6 Word Count Word Character Count ------------------------------------------------------- 1 SEA 3 2 TO 2 3 SHINING 7 4 C 1 5 HELLO 5 6 WORLD 5 --------------------------------------------------*/ char TWO_D_array[1024][100]; int wordcount, charcount; int r, c, i; int main() { char str[length]; int i, ch; ch = 0; printf("Enter a string of characters\n"); /* this is where the user */ printf("End input by pressing <CTRL-Z>\n\n"); /* will input their string */ printf("Enter string: "); UserInput(str); /* this part goes through every letter of the */ /* array and checks to see if the letter is upper case */ for (i = 0; str[i] != '\0'; i++) { str[i] = (char) Capitalize(str[i]); } NEW_2D_array(str); printf("Word Count Word Character Count\n"); printf("--------------------------------------------------\n"); while (TWO_D_array[r][c] != '\0') { printf("%-21d%s%10d\n", wordcount, TWO_D_array, charcount ); } return 0; } char NEW_2D_array(char* str) { r = c = i = 0; charcount = 0; wordcount = 0; for (i = 0; str[i] != '\0'; i++) { TWO_D_array[r][c] = str[i]; if ((str[i] == ' ') || (str[i] == '\n')) { r++; c = 0; } else { c++; } } return (TWO_D_array[r][c]); } /* this function capitalizes letters that are lower case by using math */ int Capitalize(int ch) { if (( 'a' <= ch) && (ch <= 'z' )) { return (ch + 'A' - 'a'); } else { return ch; } } /* takes input from user by cycling through every letter in the string up until ** the EOF marker, when the marker is hit, the last element in the array is set ** as the NULL character */ void UserInput(char string[]) { int ch; int i = 0; while ( (ch = getchar()) != EOF ) { if (ch != '\n') { string[i++] = (char) ch; } } string[i] = '\0'; }



LinkBack URL
About LinkBacks


