Code:
My program is now working except for the cosmetic of alignment.
Thank you guys.
Below is my latest program for those who are interested:
/*Using Microsoft Visual Studio 2005
Program to read records(ie. number,text) in a file
with the help of 'cas', MK27' and 'Adak'
Also notes I read by 'qusah'... Thank you all. YetBo
*/
Code:
#include <stdio.h>
#include <stdlib.h>
void main()
{
int Id,Number,Value,Test;
char Code,First[20],Last[20];
//Open the file using read mode
FILE *fp = fopen("Myfile.txt","r");
printf("Id Number First Last Code Value\n");
//Checks if EndOfFile
if(fp)
{
while(fscanf(fp,"%d,%d,%[^,],%[^,],%c,%d",&Id,&Number,First,Last,&Code,&Value)==6)
//or while(fscanf(fp,"%d,%d,%[a-zA-Z-'],%[a-zA-Z-'],%c,%d",&Id,&Number,First,Last,&Code,&Value)==6)
{
printf("%d %d %s %s %c %d\n",Id,Number,First,Last,Code,Value);
}
fclose(fp);
}
system("pause");
}
/* ===================================
Myfile.txt
1,3,James,Bond,a,40
2,4,Clint,Eastwood,s,52
3,5,Bart,Simpson,d,50
4,6,Ronald,Mac-Donald,a,35
5,7,Neil,O'Bryan,s,66
=====================================*/
[/code]