i have a delimited file it has
name|address|address2|phone number/n
i found this code snippet of code which i modfied to almost do what i want. the problem is i want to only count the delimited char which is '|" and '\n' but the program is counting the char instead. here is the code it is finding the first record. the program is finding records and displaying length of field i want to change program to determine record count by '\n' and display record.
#include <stdio.h>
#include <iostream>
using namespace std;
#define SIZE 30
int main()
{
char data[SIZE];
int inchar;
FILE *infile;
char *inname = "phonebook.dat";
int i;
infile = fopen(inname, "r");
if (!infile) {
printf("Couldn't open %s for reading\n");
return 0;
}
for (int count=0; count < 4; count++)
{
for (i = 0; i < SIZE - 1; i++) {
inchar = fgetc(infile);
if ((inchar == '|') || (inchar=='\n')) {
printf("%d: char count encountered\n", i); /* print is for debug purposes only */
break;
}
else {
data[i] = inchar;
}
}
data[i] = '\0';
printf("data: <%s>\n", data);
}
return 0;
}
i need help in modifing code to count the number of records the '\n' will be one record. i need program to determine how many records in file so i can loop until eof to get all records.