c - Storing strings from a text file into a two dimensional array -


i'm working on project using c , project must read in text file , store each word array. have remove punctuation off words, need use 2-dimensional array in order edit words. having trouble figuring out how words in 2-d array self. have done far:

#include <stdio.h> #include <stdlib.h> #include <string.h> #define max 1001 #define lines 81  int main(void) {     int stringsize;     int =0;     char *x[max][lines];     char str[max];     char y[max];     file *fp;      fp = fopen("twocitiesstory.txt","r");     if(fp == null) {         printf("cannot open file.\n");         exit(1);     }      while(!feof(fp)) {         for(i=0;i<max;i++){             fscanf(fp,"%s",x[i][lines]);         }     }      return 0; } 

the following line

char *x[max][lines]; 

declared 2d array of pointers. need 2d array of characters.

char x[max][lines]; 

the code reading words can simplified to:

while( < max && fscanf(fp, "%80s", x[i]) == 1 ) {    ++i; } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -