hi, i didn't get any reply probably coz ya didn't understand what i mean !
alright i'll make it simple.
i have a file in excel and i have to read from this file
here is the contents of this file
2,joined,2929828,429.6,2
4,toytoy,2929299,122.8,19
3,front shift,2299229,205,22
3,shift,1111111,222,20
...
...
...
I wrote this code
#include "stdafx.h"
#include <stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
typedef struct sales
{
int number;
char item[50];
char partnum[15];
float cost;
char day[6];
};
sales rSales[197];
int _tmain(int argc, _TCHAR* argv[])
{
FILE *fp;
fp=fopen("cust.csv","r");
char bufferCustNum[40];
char bufferCost[40];
for (int i=0; i<197; i++)
{
fgets(bufferCustNum,3,fp);
rSales[i].number=atol(bufferCustNum);
fgets(rSales[i].item,sizeof(rSales[i].item),fp);
fgets(rSales[i].part_number,sizeof(rSales[i].partnum,fp);
fgets(bufferCost,6,fp);
rSales[i].cost=atof(bufferCost);
fgets(rSales[i].day,sizeof(rSales[i].day),fp);
}
for (int j=0; j<10; j++)
{
printf("number: %i\n", rSales[j].number);
printf("Item : %s\n",rSales[j].item);
printf("partnum: %s\n",rSales[j].partnum);
printf("bufferCost: %f\n",rSales[j].cost);
printf("day: %s\n\n",rSales[j].day);
}
system("pause");
return 0;
}
all what i'm trying to do is to store each part of the stream in the specific array and display it !
but the problem is that i'm still getting the ',' between the characters...
does any one know how to remove it without changing the struct ?!
or any idea how to write a while loop to read each character untill it reaches the comma and store it ?!
example: 2,joined,2929828,429.6,2
first it read the 2 and store it in rSales.number without storing the ',' and keep going untill it reach the end of the line !
i know how to write the pseudo but i dont know how to implement in the real code !
i'll appreciate any Help:?:
thanks