I am running Windows 7 on one machine and Linux Debian on another. I am creating a C application using NetBeans. It seems to be working just find on Linux when I run it there. But when running on Windows, messes up the output somehow, kinda prints the output more than once...

My program essentially reads lines from a file and does some processing (calls exec, fork, pipe, etc..), then exits when EOF.

Also, I noticed that at the end of each line in the file, \r\n is being added to the string, is there anyway to get rid of that ?

Thank you for your help.

Sure. Line 235 is wrong. Don't use a pointer there....

Sure. Line 235 is wrong. Don't use a pointer there....

LOL!..its some assignment I have so not sure its a good thing to do posting my code...but from debugging this part of the code could potentially be the problem but still not sure..

char line[256];
FILE *fd = fopen("FILE.txt", "r");
while (1) {
        if (fgets(line, 256, fd) == NULL) {
                  break;
        } else {
                  // Do stuff...
        }

Did this happen to anyone?? or just me...

Your code is not portable. You are using functions that do not work in Windows 7

Your code is not portable. You are using functions that do not work in Windows 7

But how is that the program produces the desired output...just not in the expected format...

LOL!..its some assignment I have so not sure its a good thing to do posting my code...but from debugging this part of the code could potentially be the problem but still not sure..

char line[256];
FILE *fd = fopen("FILE.txt", "r");
while (1) {
        if (fgets(line, 256, fd) == NULL) {
                  break;
        } else {
                  // Do stuff...
        }

Did this happen to anyone?? or just me...

If FILE.txt does not exist, you continue into the read loop. Granted, based on this snippet, the if will error out, but still it's a bad practice.

And since we still don't really know what's happening, and you're not even sure if this code is the spot, we really can't help. We need details and code that exhibits the problem. Weed out everything you can until you're left with a short code segment that exhibits the error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.