Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Writing in a File using a file descriptor(File Descriptor Settings)
Writing in a File using a file descriptor [message #1818776] Fri, 27 December 2019 20:42 Go to next message
Eclipse UserFriend
Hello,
I am using eclipse 2019-09 in Ubuntu GNU Linux. For a C project I need to write Data into a file, I use a file descriptor to achieve the latter.
FILE* output_up123;
output_up123 = fopen("../../Output/up123.txt","w");
fprintf(output_up123," test text \n"); 

The code with the above file descriptor compiles, and does the job, but only when I run the binary from the linux shell. However, the binary cannot be run in Eclipse (see printscreen in attchment), this leds me to the conclusion that I have the change some eclipse settings, but I could not figure out, what I have been missing.

Can somebody please tell me, how I have to configure Eclipse, so that I can use file descriptors and run the binary from within Eclipse.

Many thanks in advance.
Andreas
  • Attachment: eclipse.png
    (Size: 207.46KB, Downloaded 205 times)
Re: Writing in a File using a file descriptor [message #1818816 is a reply to message #1818776] Sun, 29 December 2019 23:36 Go to previous messageGo to next message
Eclipse UserFriend
It's hard to tell what the current directories are during the execution
but from the Project Explorer view, the executable for FIX appears to be in directory <proj>/Bin
and the run launcher looks like it's trying to launch <proj>/Default/FIX.
The rest of the line in the console view probably would confirm this
but you've covered it up.

Verify that the run launch configuration is pointing to the proper executable.

[Updated on: Mon, 30 December 2019 00:28] by Moderator

Re: Writing in a File using a file descriptor [message #1818827 is a reply to message #1818816] Mon, 30 December 2019 02:38 Go to previous messageGo to next message
Eclipse UserFriend
thanks for your reply. The code compiles without any error. On running the executable I get no further console output (please consider the attachments).

The executable is indeed stored in the Bin directory. But the run time settings are set accordingly. Furthermore, without the file descriptors the executable can be executed from within eclipse.

I would be grateful for further tips of how I could get eclipse to run the executable, when using the file descriptors.

Many thanks in advance

Attachments:
run-timeA.png Run time settings
run-timeB.png Run time settings
run.png Console output for run
compilation.png Console output for compilation

  • Attachment: run-timeA.png
    (Size: 39.08KB, Downloaded 177 times)
  • Attachment: run-timeB.png
    (Size: 35.51KB, Downloaded 191 times)
  • Attachment: run.png
    (Size: 120.03KB, Downloaded 201 times)
  • Attachment: compilation.png
    (Size: 103.86KB, Downloaded 194 times)
Re: Writing in a File using a file descriptor [message #1818846 is a reply to message #1818827] Mon, 30 December 2019 05:38 Go to previous messageGo to next message
Eclipse UserFriend
I dunno.
I wrote a small program to do the same (more or less) and it worked OK.
#include <stdio.h>

int main() {
	FILE *output;
	output = fopen("../output.txt","w");
	if (output == (void*)0)
		printf("Error opening output %d\n",errno);
	else
		printf("Open ok\n");

	fprintf(output,"Some stuff\n");
	printf("Wrote one line to output\n");
	fclose(output);

	return 0;
}

index.php/fa/37051/0/
index.php/fa/37052/0/

The negative output is an error return code.
You may be getting an error when you try to write?
Or something else in your code is returning the -1?
You forgot to return a zero?

You aren't printing anything so how do you know it didn't write the file?
You normally don't see the return code when running from a terminal.

Try changing the main temporarily to only write but print any error return like I do.
Check that the working directory in the Arguments tab is correct.
index.php/fa/37054/0/

[Updated on: Mon, 30 December 2019 05:55] by Moderator

Re: Writing in a File using a file descriptor [message #1818851 is a reply to message #1818846] Mon, 30 December 2019 07:33 Go to previous message
Eclipse UserFriend
This was it, I did not choose the right working directory in the Arguments tab of the run time settings.
Many thanks for your help!!!
cheers
Previous Topic:GTK integration in Eclipse on Ubuntu VM
Next Topic:Debugger perspective : How to show a variable content as it prints using << ?
Goto Forum:
  


Current Time: Sat Jun 21 08:01:39 EDT 2025

Powered by FUDForum. Page generated in 0.05836 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top