I'm having trouble with the output.
I'm supposed to:
- Enter a csv file (with info in it)
- Read the file
- Go through it one by one and sort it into a structure
- Sort it by the customer id (which is also used in the csv file)
- Print it out in this format - cust_num;item;part_number;cost;date
- And put each of the sales (in that format) back into a .txt file
I've done all of this already. Its done so that the output prints out in the cmd window and into the txt file.
First Problem;;
This is the output in the cmd window:
0;tainless Steel Exhaust System;1006266;462.350006;29As you can see -- its missing the first letter of the item name. But when it gets to customer number 10, the whole name is shown:
1;eat Cover;1023589;15.250000;27
1;HC Valve;1056658;23.500000;1
1;uel Pump;1091662;56.180000;24
1;ynchomesh;1057073;62.799999;24
1;am Shaft;1037371;98.699997;1
10;Rocker Cover Housing;1030241;42.169998;21I think it may be how I capture the customer number:
10;Hub Caps;1009393;50.029999;24
10;Stainless Steel Exhaust System;1068170;462.350006;27
10;Spanner Set;1056456;15.500000;7
Expand|Select|Wrap|Line Numbers
- int GetCustomer(FILE *file, int *number)
- {
- int i;
- char buffer[80];
- // read in customer number
- for(i = 0; i<=2; i++)
- {
- buffer[i] = fgetc(file);
- }
- buffer[i] = '\0';
- // Convert string to int
- *number = atoi(buffer);
- return 0;
- }
Expand|Select|Wrap|Line Numbers
- buffer[i] = '\0';
- to
- buffer[i+1]='\0';
Second problem;;
This is what part of the output in the txt file looks like:
tainless Steel Exhaust System ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1006266 ÌÌÌÌÌÌÌÌÌÌÍ,çC29 ÌÌÌÌÌ eat Cover ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1023589 ÌÌÌÌÌÌÌÌÌÌ tA27 ÌÌÌÌÌ HC Valve ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1056658 ÌÌÌÌÌÌÌÌÌÌ ¼A1 ÌÌÌÌÌÌ uel Pump ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1091662 ÌÌÌÌÌÌÌÌÌÌR¸`B24 ÌÌÌÌÌ ynchomesh ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1057073 ÌÌÌÌÌÌÌÌÌÌ33{B24 ÌÌÌÌÌ am Shaft ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1037371 ÌÌÌÌÌÌÌÌÌÌffÅB1 ÌÌÌÌÌÌ adiator Cap ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1036043 ÌÌÌÌÌÌÌÌÌÌÃõPA7 ÌÌÌÌÌÌ xle ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1089 737 ÌÌÌÌÌÌÌÌÌÌÍÌÙC6 ÌÌÌÌÌÌ xle ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1093 533 ÌÌÌÌÌÌÌÌÌÌÍÌÙC17 ÌÌÌÌÌ iring harness ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1047566 ÌÌÌÌÌÌÌÌÌÌ €ðB28 ÌÌÌÌÌ adiator Cap ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1021754 ÌÌÌÌÌÌÌÌÌÌÃõPA9 ÌÌÌÌÌÌ ear Mirror ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1050480 ÌÌÌÌÌÌÌÌÌÌ aB9 ÌÌÌÌÌÌThis is what it looks like when i get to the customer 10 sales:
Spanner Set ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ1056456 ÌÌÌÌÌÌÌÌÌÌ xA7 ÌÌÌÌÌÌI asked my teacher about it and she said that it may be how I've had the program to read in the csv file:
Expand|Select|Wrap|Line Numbers
- //declares a pointer of the type file
- FILE *file, *output;
- sales mysales[196];
- //Opens Sales.csv for reading
- file = fopen("sales.csv", "r");
- // Check if file opened
- if(file == NULL)
- {
- printf("can't open file");
- return 0;
- }
- int i = 0, j = 0;
- // while not end of file read and sort
- while (!feof(file))
- {
- GetCustomer(file, &mysales[i].cust_num);
- get_field(file,',',mysales[i].item);
- get_field(file,',',mysales[i].part_number);
- get_field_float(file,',', &mysales[i].cost);
- get_field(file,',',mysales[i].date);
- i++;
- }
Before I editted/updated the file, earlier when I was going through it, the output in the txt file was the same as the output (above) in the cmd window. But now its got all that Ì character and weird formatting. (I unfortunately saved over it :S)
If someone could please help me get on the right track, or maybe point out where its wrong, i'd really appreciate it. [I hope there's enough information here to get you going. =)]