Hi all,
I have a code to read the records using a file,also the file has got unnecessary stuff that needs to be ignored.
I am able to read and write only the first record,next am able to read and write only the second "record name" but not the whole record.
Pls help me out to get the desired result.
I am using unix machine/putty to run the code.
Also,pls check the csp.txt file attached.
Regards,
Srikanth.
This is my code::
#include<stdio.h>
#include<string.h>
void fetch_word();
struct rec_name
{
char name[10];
}rec[2];
char arr[120]={0};
char *arr1;
FILE *fp;
char *substring(size_t start, size_t stop, const char *src, char *dst, size_t size)
{
int count = stop - start;
if ( count >= --size )
{
count = size;
}
sprintf(dst, "%.*s", count, src + start);
return dst;
}
int main()
{
char ch,p[10];
int i=0,x,m;
#define MAX 120
char buff[MAX];
arr1=(char *)malloc(sizeof(char)*150);
fp=fopen("csp.txt","r");
while(!feof(fp))
{
fgets(buff,MAX,fp);
if(strstr(buff,"RECORD NAME:")!=NULL)
{
for(i=1;i<2;i++)
{
substring(65, 75, buff,p,sizeof(p));
strcpy(rec[i].name,p);
printf("RECD NAME::%s\n",rec[i].name);
}
}
if( ((strstr(buff,"DESCRIPTION"))!=NULL) )
{
printf("INTO THE RECORDS NOW:");
while(strstr(arr,"RECORD DEFINITIONS")==NULL)
{
fgets(arr,120,fp);
printf("\n%s",arr);
}
}
}
fclose(fp);
}