Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Problem With C/C++ "fgets" on eclipse, Help !(when i use fgets, the program doesn't debug until i write the fget value on the console.)
Problem With C/C++ "fgets" on eclipse, Help ! [message #1043257] Wed, 17 April 2013 13:28 Go to next message
programmer best is currently offline programmer bestFriend
Messages: 1
Registered: April 2013
Junior Member

Hi,
i have installed gcc & eclipse on windows.
when i use fgets, the program doesn't debug until i write the fget value on the console.

code:-
#include <stdio.h>

enum { max_string = 127 };
static char string[max_string + 1]="";

int main(int argc, char ** argv ){
	printf("type string: ");
	fgets(string, max_string, stdin);
	printf("your string is %s\n", string);
	return 0;

}


this is a simple c code to print "type string:", then fgets reads input to print it later.
so the right sequence of this program supposed to be like this:-
1. print "type string:" on console
2. fgets reads input and store it on "string" variable
3. print the "string" value

now the problem is the program runs on this sequence.
1. blank console page without printing anything and fgets reads input first
2. print everything written before fgets and after it

any help ?
Re: Problem With C/C++ "fgets" on eclipse, Help ! [message #1707716 is a reply to message #1043257] Tue, 08 September 2015 17:03 Go to previous message
Yan Karlo is currently offline Yan KarloFriend
Messages: 1
Registered: September 2015
Junior Member
Hi,
Put this on the beginning : setvbuf(stdout, NULL, _IONBF, 0);
It´s worked for me.

Rgds
Previous Topic:Running into errors
Next Topic:Debug com MPLAB
Goto Forum:
  


Current Time: Wed Feb 10 20:26:02 GMT 2016

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

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