Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Writing data into a txt file, C
Writing data into a txt file, C [message #1835782] Sat, 12 December 2020 12:03 Go to next message
Kamil Sawicki is currently offline Kamil SawickiFriend
Messages: 2
Registered: December 2020
Junior Member
I am trying to save data into txt file in eclipse.
However upon calling `fopen` function I get such error while building:
main.c:(.text.startup.main+0xa4): undefined reference to `fopen'


    char n[] = "6E436C703186B19CBC6BFD77DFD8FF3D85F7274793A0A";

	char subn[40];
	strncpy ( subn, n, 5);
	subn[5] = '\0';

	USART_TX_String(subn);
	_delay_ms(1000);

	//Zapis do pliku
	int num;

	FILE *fptr;
	fptr = fopen("hexnumbers.txt","w");
    if(fptr == NULL)
    {
        printf("Error!");
        exit(1);
    }
    printf("Enter num: ");
    scanf("%d",&num);
    fprintf(fptr,"%d",num);
    fclose(fptr);
Re: Writing data into a txt file, C [message #1835793 is a reply to message #1835782] Sun, 13 December 2020 07:00 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Quote:
I am trying to save data into txt file in eclipse.
However upon calling `fopen` function I get such error while building: undefined reference to `fopen'

Actually, you are trying to save data to a text file in a program you wrote using Eclipse.
Where is that program supposed to run?
Is fopen supported there?

Re: Writing data into a txt file, C [message #1835797 is a reply to message #1835782] Sun, 13 December 2020 15:06 Go to previous messageGo to next message
Joost Kraaijeveld is currently offline Joost KraaijeveldFriend
Messages: 273
Registered: July 2009
Senior Member
Based on your usage of USART_TX_String you are writing a program for some Atmel environment (Arduino?).

As stated on https://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html: "Also, since there is no notion of "file" whatsoever to avr-libc, there is no function fopen() that could be used to associate a stream to some device. "




Cheers,

Joost
Re: Writing data into a txt file, C [message #1835803 is a reply to message #1835793] Sun, 13 December 2020 17:27 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
David:

This may be a bit off-topic. Could you set a fixed instruction to posters to indicate clearly if a problem is in cross-compilation and/or single-chip embedded target?

It seems that the OP does not realize that an AVR does not have a file system.


--

Tauno Voipio
Re: Writing data into a txt file, C [message #1835812 is a reply to message #1835803] Mon, 14 December 2020 04:46 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Tauno,

I do agree that a sticky post with guidelines would be nice.
I think only the moderator can do this. I'm not a moderator.

There are a lot of first time posters who really don't understand the role Eclipse plays.
However, a sticky reminding posters to say if cross-compilation is being employed would go a long way.
Re: Writing data into a txt file, C [message #1835823 is a reply to message #1835812] Mon, 14 December 2020 12:06 Go to previous message
Kamil Sawicki is currently offline Kamil SawickiFriend
Messages: 2
Registered: December 2020
Junior Member
Iam realy grateful for all the replies and In fact I am a first time poster here and a newbie in AVR world therefore I am here asking you questions.

@David Vavra
David Vavra wrote on Sun, 13 December 2020 07:00
Quote:
I am trying to save data into txt file in eclipse.
However upon calling `fopen` function I get such error while building: undefined reference to `fopen'

Actually, you are trying to save data to a text file in a program you wrote using Eclipse.
Where is that program supposed to run?
Is fopen supported there?


Since I posted that it been couple days and now Iam aware that fopen function is not supported.
All I wanted to do is to preview how data would save into SD card.
I used my experience from other IDE's and didnt give to much thought what I am Really trying to do here, now Iam aware how bizzare my Idea was.
I decided to go streight to saving data on SD card with help of FatFs libraries.

@Joost KraaijeveldFriend
Quote:
Based on your usage of USART_TX_String you are writing a program for some Atmel environment (Arduino?).
As stated on https://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html: "Also, since there is no notion of "file" whatsoever to avr-libc, there is no function fopen() that could be used to associate a stream to some device. "

Yes, yes it is Atmels environment but its no Arduino, its standalone Atmega32 connected by SPI to PC with help of a USB programator.
And as I typed above, I made myself more familiar with manual for avr library and decided to forfeit that idea and get straight to it.
Previous Topic:Linux terminal as Debug console
Next Topic:How to display mouse-over tooltip on an imported project?
Goto Forum:
  


Current Time: Thu Apr 25 22:53:01 GMT 2024

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

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

Back to the top