arrays - C Programming Crash -


for reason, program crash error:

1 [main] popular names 6428 cygwin_exception::open_stackdumpfile: dumping stack trace popular names.exe.stackdump

i reading in txt has list of names amount of people given name within particular year. (e.g. yob1920.txt = names given newborns in year 1920). big component have use pointers pass 2d arrays hold names , popularity of each name.

my program first reads in file, reads line, , when reaches read_in_line function, take name of line , store char array string. (e.g. mary,f,70980<- care "mary")

from here, want store name names 2d array if not stored there already. afterwords, want update names popularity ranking in ranks 2d array current year.

#include <stdio.h> #include <string.h> #define row 400 #define name_col 50 #define rank_col 10 void read_in_files(char **names, int **ranks); void read_in_file(char **names, int **ranks, file *infile, int year); void read_in_line(char **names, int **ranks, char *line, int count, int year); void sort_array(); void create_output();   int main(void) {     setvbuf(stdout, null, _ionbf,0);     char names[row][name_col]; //holds strings of names     int ranks[row][rank_col + 1]; //hold popularity of names     read_in_files(names, ranks);      return 0; }  void read_in_files(char **names, int **ranks) {     file *infile1 = fopen("yob1920.txt","r"); //opens file read     read_in_file(names, ranks, infile1, 0); //contains names    }  void read_in_file(char **names, int **ranks, file *infile, int year) {     int count = 0, i;     char line[100000];      while(count != 100) {         fscanf(infile, "%s", line); //grab line txt , store in line array         read_in_line(names, ranks, line, count, year);         memset(line, '\0', sizeof(line)); //clear line array         count++; //read first 100 lines     } }  void read_in_line(char **names, int **ranks, char *line, int count, int year) {     char temp;     char save[30];     int = 0;     while(1) { //take name line         temp = line[i];         if (isalpha(temp)) {             save[i] = temp;         } else {             break;         }         i++;     }      for(i = 0; < row; i++) { //search names array          if(strstr(names[i], save)) { //the current name stored in save array             break;         }     }      if (i == row - 1) { //if not found, add name         for(i = 0; < row; i++) { //add end of list             if(names[i] == '\0') { //of names                 break;             }         }         names[i] = save; //adds name     }      ranks[i][year] = count; //update popularity rank based on year of                             //txt file , ranking in file. }  void sort_array() { //not implemented  }  void create_output() { //not implemented  } 


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -