Below is the code I have.. I need to make it so it copes with file lines of any length but currently it works with only a fixed number
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
// check num of args
if(argc != 4)
{
fprintf(stderr,"Usage is %s <number>\n", argv[0]);
}
else
{
FILE *fileOne =fopen( argv[2], "r");
FILE *fileTwo =fopen( argv[3], "r");
char *sep = argv[1];
char LineA[512];
char LineB[256];
if ( fileOne == 0 || fileTwo == 0)
{
/* error*/
fprintf(stderr, "Error: Can't open file");
}
else
{
while(*LineA || *LineB)
{
char *p;
if(fgets(LineA, sizeof(LineA), fileOne))
{
if((p = strchr(LineA, '\n')))
*p = '\0';
}
else
*LineA = '\0';
if(fgets(LineB, sizeof(LineB), fileTwo))
{
if((p = strchr(LineB, '\n')))
*p = '\0';
}
else
*LineB = '\0';
if(*LineA || *LineB)
{
printf("%s%s%s\n", LineA, sep, LineB);
}
}
}
}
return 0;
}
thanks in advance for any help advice on this... really need it!