i'm having issues regarding use of fscanf()
. main objective take each word input file, , place them sequentially 2d array of char
, so:
ex: words[0][] = words[1][] = quick words[2][] = brown words[3][] = fox ...
i've tried other methods, such fgetc()
, placing each character in spot nested for
loops. seems overkill when there more streamlined methods. way stands, @ each iteration, wordlist
contains next word read. how go assigning current value of wordlist(at each iteration) sequentially 2d array?
my current (relevant) code:
int main (int argc, char *argv[]) { file *fptr; char words[200][50]; char *wordlist; if (fptr = fopen(argv[2], "r")) { // if file exists, open reading while(fscanf(fptr, "%49s", wordlist) == 1) { // read in strings main file wordlist // strcpy(words, wordlist); } else { fprintf(stderr, "%s", "error: file not opened.\n"); return 0; } fclose(fptr); return 0; }
the maximum words read can safely assumed less 200. length of each word can assumed less 50 characters.
Comments
Post a Comment