c - Char Pointer Arrays -


itemprop = "text">

I have a skeletal code that allows me to read a list of words with a four indicator array (wordslist) from a text file Lets have been given in. I tried to move the values ​​to the 2D array (word), it compiles right away, but when I try to print the array, I am getting new lines instead of stars.

I think the problem may need to be done with the indicators and can be especially on line 55 but I am not sure what I am doing.

  // Lab 10 Extender Locker skeleton code # include & lt; Stdio.h & gt; #include & lt; String.h & gt; # Include & lt; Ctype.h & gt; # Include & lt; Stdlib.h & gt; # Include & lt; Ncurses / ncurses.h & gt; #define MAXWORDS 100 #define WORDLEN 11 #define DEBUG 0 // Set to disable debug output from Word word (four * wl [MAXWORDS], char * filename); // reads the word from the file // wl and trim the white space from the end / s / s on the right side to trim the white spot from zero trim (four * s); Zero print word (four * words, int punctuation, int rows, int column); Int main (int argc, char * argv []) {char * wordlist [MAXWORDS]; Int wordCount; Int i, j, k = 0; Int column = 5; Int rows; WordCount = Read Word (word list, arguments [1]); If (DEBUG) {printf ("% s read word% s from \ n", word count, argue [1]); For (i = 0; i  = 0)) {s [x] = '\ 0'; X--; }} Int readWords (char * wl [MAXWORDS], char * filename] {int numread = 0; Four line [wordlen]; Four * p; FILE * fp = fopen (filename, "r"); While (! Fif (FP)) {p = fgets (line, verdelen, FP); If (! FIF (FP) & P! = Null) {trim (line); Wl [numread] = (four *) malloc (strlen (line) +1); Strcpy (wl [numread], line); Numread ++; }} Fclose (fp); Return digits}  

Code: Text file:

Output:

  $ ./lab10-3 wordslist.txt 16  

Just before you print out your 2D array here: For the (i = 0; i & lt; rows; i ++) for

 {j = 0; j & lt; column; j ++} {if (k & Lt; = words) {printf ("% 15s" words [i] [ja]); K ++; }} Printf ("\ n"); }  

, 0 needs to be reset to k so that way:

  k = 0; For {= (; J = 0; j & lt; column; J ++) {if (k & lt; = words) {printf ("%") for {I = 0; I & lt; rows; i ++} 15s "words [i] [ja]); K ++; }} Printf ("\ n"); }  

otherwise your if condition will always evaluate the wrong, and you will never print anything, since the last loop has already used it to count How many words do you have for


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -