You are on page 1of 1

#include<stdio.h> int main() { //FILE* fp = fopen("census.txt","r"); //char aLine[60]; //FILE* sorted = fopen("censusSorted.

txt","a"); char aLine[800]; char string[200]; memset(string,0,sizeof string); FILE* fp = fopen("census.txt","r"); FILE* sorted = fopen("censusSorted.txt","w"); while(fgets(aLine,sizeof(aLine),fp)) {; //printf("pass %d\n", sizeof(aLine)); //printf("%s\n",aLine); char *skip1 = strtok (aLine,","); char *city = strtok (NULL," "); if(strcmp(city,"St.") == 0) // if it St. we need city na me { char *cityskip = strtok (NULL," "); //char *cityext = strtok (NULL," "); strcat(city,cityskip); } char *skipProvince = strtok (NULL,"CMA"); char *skipProvince1 = strtok (NULL,","); char *skipProvince2 = strtok (NULL,","); char *skipProvince3 = strtok (NULL,","); char *population = strtok (NULL,","); strcpy(string,city); strcat(string," "); strcat(string,population); strcat(string,"-"); strcat(string,"\n"); printf("String is : %s\n", string); fputs(string , sorted ); } fclose(fp); fclose(sorted); return 0; }

You might also like