473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Output of nested scanf statements in a printf

1
iam an amatuer who is trying to get into the C programming but I have many doubts please help me. If scan is function than what value does scanf returns and similarly about printf what is the output of this statement
main()
int i;
printf(""%d",scanf("%d",scanf("%d",&i));
}
Jun 21 '07 #1
4 4287
DeMan
1,806 1GB
Hi neotan,

Welcome to TSDN. I am sure you will find a wealth of answers from the experts in the various forums.
I will move this question to the c(++) forum for you. In future, you can access the forums directly by selecting from the different tabs on the blue bar near the top of your screen.

I hope the c/c++ experts can be of assistance!
Jun 21 '07 #2
JosAH
11,448 Expert 8TB
iam an amatuer who is trying to get into the C programming but I have many doubts please help me. If scan is function than what value does scanf returns and similarly about printf what is the output of this statement
main()
int i;
printf(""%d",scanf("%d",scanf("%d",&i));
}
Bookmark this link. It's a nice reference for your C and/or C++ development.
scanf returns the number of items that were succesfully scanned and printf returns
the number of characters that were printed.

Your code example most likely produces a core dump because its second, third
etc. (if applicable) arguments are supposed to be addresses where the scan
results should be stored.

kind regards,

Jos
Jun 21 '07 #3
archonmagnus
113 100+
In order to test the return values, try this code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int main (void)
  4. {
  5.     int i;
  6.     printf("Enter an integer value: ");
  7.  
  8.     int j = scanf("%d", &i);
  9.     int k = printf("Items Scanned: %d", j);   // Outputs "1"
  10.  
  11.     printf("\nItems Printed: %d\n", k);     // Outputs "16" (Total character outputs from last printf)
  12.  
  13.     return 0;
  14. }
  15.  
Jun 21 '07 #4
sicarie
4,677 Expert Mod 4TB
neotan-

Please also have a look at our Posting Guidelines, including those that request you use good thread titles, and code tags.

I've changed this thread title, please let me know if you don't think it adequately describes your issue.

Thanks, and welcome!
Jun 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David | last post by:
Could someone help me turn this program into a program that accepts files(database) as an input and writes to a file as method of saving the database information? #include <stdio.h> #define n...
5
by: Tom Lam lemontea | last post by:
Hi all, This is my very first post here, I've seriously tried some programming on C, and shown below is my very first program(So you can expect it to be very messy) that I wrote after I've learned...
10
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our...
8
by: Gregc. | last post by:
Hi Sorry to bother you gusy with such a basic question, but I am working on a conversion program. I've got most of it down, but I am having trouble with the output: *Dollar Conversion...
2
by: chiefs | last post by:
I'm a beginner in C++!! #1-Dont know how to loop end when int q(entered); int q is a very large # when ran: printf("\n%i#of Questions\n", q); #2-is the line "how many questions Right"?...
11
by: aljaber | last post by:
hi, i am facing a problem with my program output here is the program /*********************************************\ * CD Database * * ...
5
by: chevon1920 | last post by:
Hi, I just have a question for anyone who can help. I am trying to write a program that will print to a file. The program has a while loop so that when I run it, it should print to the file each time...
4
by: S. | last post by:
Hi all, I have the requirement that I must pass-by-reference to my function addStudent() and getAge() functions where my getAge() function is within the addStudent() function. I am able to...
2
by: subramanian100in | last post by:
Consider the following program named as x.c #include <stdlib.h> #include <stdio.h> int main(void) { unsigned int u; char str;
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.