Sponsored Content
Top Forums Programming disturbing problem with PRINTF() !! Post 16972 by brain_processin on Saturday 9th of March 2002 12:04:15 PM
Old 03-09-2002
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 Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

awk printf problem

Hi Friends, Can anyone guide me how to compute sum of column4 from the below file x using awk command? when i do using awk I'm getting sum 7482350198352648.000000 which is not accurate. $ cat x 56,232,dfgjkhdfj,,56,anand 56,22,dfgjkhdfj,7482347823453123.97834 ,56,Khan 56,23,dfgjkhdfj, ... (6 Replies)
Discussion started by: krishna
6 Replies

2. Shell Programming and Scripting

perl: printf indentation problem

hi all, im having a problem with using perl printf. my requirement is to print a string (like ) at the right most end of the screen. i tried this perl script, but it fails with an error; #!/usr/bin/perl use strict; use warnings; my $scrW = 0; my $str = `stty size`; # get the... (5 Replies)
Discussion started by: wolwy_pete
5 Replies

3. Shell Programming and Scripting

printf problem

I have the following code: $ awk '{ printf "%-10s %s\n", $1, $2, $3, $4, $5, $5, $6 }' file i can only print the first 2 elements ($1,$2). How can i print all the elements to appear like this: aardvark 5555553 jhfjhfjkg efiigig ejkfjkej wjkdjk alpo-net 5553412 ... (2 Replies)
Discussion started by: DDoS
2 Replies

4. Shell Programming and Scripting

Awk printf problem

Hi, I've got a basic problem using printf statement in awk. I want to write float values with always 8 characters width. Examples : 1.345678 12.45678 123.4567 1234.678 -23.5678 -2.45678 -23456.8 ..... I cannot find the right printf format %8.1f, %7.5f.... Can anyone help ?... (4 Replies)
Discussion started by: cazhot
4 Replies

5. Shell Programming and Scripting

Printf problem

I am having a major problem with printf, The more I pad it, the less I see :( The problem is in the first function, report Am I ruining output somewhere? I wont print out the names propely, it cuts them off or deletes them completely :( #!/bin/bash report() { printf "%-10s" STUD# ... (2 Replies)
Discussion started by: L0ckz0r
2 Replies

6. Shell Programming and Scripting

printf problem

In one of the scripts I am using pintf function as following printf "%s%s%s\n" "$f1" "$f2" "$f3" f3 variable contains a string of 10 characters. However it has value first 7 character and last 3 characters are empty. Example Aaaaaaa<3 spaces> bbbbbbb<3 spaces> ccccccc<3 spaces>... (4 Replies)
Discussion started by: varunrbs
4 Replies

7. Shell Programming and Scripting

problem with printf in shell script

i have written small script as follows: name="hi hello" printf "%-20s" $name This gives me strange output. -20s format is applied on both word of string. i.e it displays both word hi and hello in space of 20 length. I want to display entire string "hi hello" in length of 20 space. plz... (2 Replies)
Discussion started by: admc123
2 Replies

8. Shell Programming and Scripting

Problem with printf in UNIX KSH shell

Hi ALL, I am using SunOS 5.9 and KSH(bin/ksh) The problem am facing is error message diaplyed on screen printf: 12099415.79 not completely converted printf: + expected numeric value printf: 11898578.29 not completely converted When i try printing with The output is... (6 Replies)
Discussion started by: selvankj
6 Replies

9. Solaris

Constant disturbing messages????

Hi friends, I am new to Solaris, I have just managed to install Solaris 10 under VirtualBox. As I use the system, I constantly get some very disturbing error messages on my screen, I hope you will help me remove them. Messages are # syslogd: line 24: WARNING: loghost could not be resolved ... (6 Replies)
Discussion started by: gabam
6 Replies

10. Shell Programming and Scripting

Problem running plsql using printf command on bash shell

I am running plsql using printf on a shell, but i am getting some strange error, can someone point what exactly am i missing, $ echo $SHELL /bin/bash $ printf " > SET serveroutput ON trimspool on feed off echo off > declare > p_val number; > d_val varchar2(10); > begin > SELECT... (1 Reply)
Discussion started by: kamauv234
1 Replies
SETBUF(3)						     Linux Programmer's Manual							 SETBUF(3)

NAME
setbuf, setbuffer, setlinebuf, setvbuf - stream buffering operations SYNOPSIS
#include <stdio.h> void setbuf(FILE *stream, char *buf); void setbuffer(FILE *stream, char *buf, size_tsize); void setlinebuf(FILE *stream); int setvbuf(FILE *stream, char *buf, int mode , size_t size); DESCRIPTION
The three types of buffering available are unbuffered, block buffered, and line buffered. When an output stream is unbuffered, information appears on the destination file or terminal as soon as written; when it is block buffered many characters are saved up and written as a block; when it is line buffered characters are saved up until a newline is output or input is read from any stream attached to a terminal device (typically stdin). The function fflush(3) may be used to force the block out early. (See fclose(3).) Normally all files are block buffered. When the first I/O operation occurs on a file, malloc(3) is called, and a buffer is obtained. If a stream refers to a terminal (as stdout normally does) it is line buffered. The standard error stream stderr is always unbuffered by default. The setvbuf function may be used on any open stream to change its buffer. The mode parameter must be one of the following three macros: _IONBF unbuffered _IOLBF line buffered _IOFBF fully buffered Except for unbuffered files, the buf argument should point to a buffer at least size bytes long; this buffer will be used instead of the current buffer. If the argument buf is NULL, only the mode is affected; a new buffer will be allocated on the next read or write opera- tion. The setvbuf function may only be used after opening a stream and before any other operations have been performed on it. The other three calls are, in effect, simply aliases for calls to setvbuf. The setbuf function is exactly equivalent to the call setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ); The setbuffer function is the same, except that the size of the buffer is up to the caller, rather than being determined by the default BUFSIZ. The setlinebuf function is exactly equivalent to the call: setvbuf(stream, (char *)NULL, _IOLBF, 0); RETURN VALUE
The function setvbuf returns 0 on success. It can return any value on failure, but returns nonzero when mode is invalid or the request cannot be honoured. It may set errno on failure. The other functions are void. CONFORMING TO
The setbuf and setvbuf functions conform to ANSI X3.159-1989 (``ANSI C''). BUGS
The setbuffer and setlinebuf functions are not portable to versions of BSD before 4.2BSD, and are available under Linux since libc 4.5.21. On 4.2BSD and 4.3BSD systems, setbuf always uses a suboptimal buffer size and should be avoided. You must make sure that both buf and the space it points to still exist by the time stream is closed, which also happens at program termi- nation. For example, the following is illegal: #include <stdio.h> int main() { char buf[BUFSIZ]; setbuf(stdin, buf); printf("Hello, world! "); return 0; } SEE ALSO
fclose(3), fflush(3), fopen(3), fread(3), malloc(3), printf(3), puts(3) Linux 2001-06-09 SETBUF(3)
All times are GMT -4. The time now is 06:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy