The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
perl: printf indentation problem wolwy_pete Shell Programming and Scripting 5 03-27-2008 08:09 PM
Problem with "printf" Lokesha UNIX for Dummies Questions & Answers 1 02-07-2008 10:20 AM
printf mirusnet Shell Programming and Scripting 4 01-23-2008 10:09 AM
printf arunviswanath High Level Programming 2 09-19-2007 10:31 PM
awk printf problem krishna UNIX for Advanced & Expert Users 6 11-18-2003 11:59 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-09-2002
brain_processin brain_processin is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 5
Lightbulb disturbing problem with PRINTF() !!

hello everybody,
here is my problem:
________________________________________
#include <stdio.h>

int main()
{
int i=10;
printf("value is %i",i);
return 0;
}
_________________________________________

when i compile and execute, nothing appears on screen!!
but if i replace the printf line with this one:
printf("value is %i\n",i); // i just added a \n
then i can see the line displayed on my screen.
ok, that's allright, but what if i want to display something _without_ the \n ?

someone told me it was a classic buffer problem and adviced me to use fflush()
but when i write:
printf("value is %i",i); fflush(stdout);
nothing happens. i also tried to put fflush(stdout) before the printf, because i don't know how to use this function correcly, but nothing happened.

can someone explain me what's the matter?!!
im using Linux Mandrake 8.0
thanks
  #2 (permalink)  
Old 03-09-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,123
My guess is that your shell is overwriting the data with its prompt. Try this:
printf("value is %d", i);
fflush(stdout);
sleep(10);
  #3 (permalink)  
Old 03-10-2002
brain_processin brain_processin is offline
Registered User
  
 

Join Date: Mar 2002
Posts: 5


that's great, you were right!

nice guess. now i finally understand what's happening, thank you!


anyway im disapointed with this bash shell...
is there a way to set the bash so that it doesn't overwrite the data?
Closed Thread

Bookmarks

Tags
linux mandrake

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0