(I am so close to finishing my 1st large C programme for my new boss I can almost taste it, yet errors crop up)
I have written a small C function to copy/move files from one location to another (on the same server). It appears to work ok except that an extra line break in added after every line.
The original
Code:
"SEW_AU","PICKLIST","Delivery_no","106066841","Order_no","1142771","Customer_no","100729","FILLER","000","REPORT","PICKLIST","\TestingTiffMoves\AU\PICKLIST\0000544B.TIF"
"SEW_AU","PICKLIST","Delivery_no","106066854","Order_no","1142781","Customer_no","100042","FILLER","000","REPORT","PICKLIST","\TestingTiffMoves\AU\PICKLIST\0000544C.TIF"
"SEW_AU","PICKLIST","Delivery_no","106066814","Order_no","1142752","Customer_no","105617","FILLER","000","REPORT","PICKLIST","\TestingTiffMoves\AU\PICKLIST\0000544D.TIF"
"SEW_AU","PICKLIST","Delivery_no","106066851","Order_no","1142779","Customer_no","103841","FILLER","000","REPORT","PICKLIST","\TestingTiffMoves\AU\PICKLIST\0000544E.TIF"
After the moving
Code:
"SEW_AU","PICKLIST","Delivery_no","106066841","Order_no","1142771","Customer_no","100729","FILLER","000","REPORT","PICKLIST","\TestingTiffMoves\AU\PICKLIST\0000544B.TIF"
"SEW_AU","PICKLIST","Delivery_no","106066854","Order_no","1142781","Customer_no","100042","FILLER","000","REPORT","PICKLIST","\TestingTiffMoves\AU\PICKLIST\0000544C.TIF"
"SEW_AU","PICKLIST","Delivery_no","106066814","Order_no","1142752","Customer_no","105617","FILLER","000","REPORT","PICKLIST","\TestingTiffMoves\AU\PICKLIST\0000544D.TIF"
"SEW_AU","PICKLIST","Delivery_no","106066851","Order_no","1142779","Customer_no","103841","FILLER","000","REPORT","PICKLIST","\TestingTiffMoves\AU\PICKLIST\0000544E.TIF"
This extra line break causes later programs to fail.
The code seems to be relatively simple
The copy function
Code:
void copy(char *srcFileName, char *dstFileName)
/* This routine takes 2 file names as parameters. It will copy the source file, srcFileName, to the destination file, dstFileName. */
{
FILE *fsrc, *fdst;
char ch;
fsrc=fopen(srcFileName, "rb");
if (fsrc==NULL) {
printf("Couldn't open file %s for reading.", fsrc);
exit (0);
}
fdst=fopen (dstFileName, "w");
if (fdst==NULL) {
printf("Couldn't open file %s for writing.", fdst);
exit (0);
}
//copying file here
while(!feof(fsrc)) {
ch = fgetc(fsrc);
if(ferror(fsrc)) {
printf("Read Error to %s\n", fsrc);
clearerr(fsrc);
break;
} else {
if(!feof(fsrc))
fputc(ch, fdst);
if(ferror(fdst)) {
printf("Write Error to %s\n", fdst);
clearerr(fdst);
break;
}
}
}
fclose (fsrc);
fclose (fdst);
}
The copy function is called from this snippet
Code:
if (tiffFile != NULL) {
while (fgets(tiffLine, size, tiffFile)!=NULL) { //loop for reading a line up of "moveTIFF.dat" to end of file
tiffLine[strcspn ( tiffLine, "\n" )] = '\0'; // This line removes the '\n' off the string
sstrncpy(dest, tiffLine, size);
if (
(end_of_path = strrchr(dest, '\\')) != NULL
||
(end_of_path = strrchr(dest, '/')) != NULL
) {
++end_of_path;
sstrncpy(tiff_file, end_of_path, size);
*end_of_path = 0;
tiff_file[size] = '\0';
strncat(dest, index_file, size);
copy(tiff_file, tiffLine);
}
}
fclose(tiffFile);
}
Why/where is the extra line break being added?
I hope their is enough info present.
(If I am totally up the creek and there is an easier, cleaner way to do this don't be afraid to hurt my feelings and tell me )