473,666 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is the difference between these two programs

48 New Member
#include <stdio.h>

int main(void) {
int i;
char a[3];
for(i=0;i<3;i++ )
scanf("%d",a[i]);
printf("%d",ato i(a));
return 0;
}
this is giving the output as 0 but if i take input as a[3]={'1','2,'3'} it is giving correct what is difference in usage of atoi
Jan 30 '15 #1
2 1154
weaknessforcats
9,208 Recognized Expert Moderator Expert
Have you tried %c in the scanf since you have a char array? The %d is for int.
Jan 30 '15 #2
donbock
2,426 Recognized Expert Top Contributor
The "%d" argument tells scanf to store an integer value, but you tell it to store that integer value in a char. An integer is too big to fit in a char so scanf ends up writing past the end of array a. Something weird is going to happen.

The second argument to scanf is the address where the integer is to be stored. Your second argument is a[i]. That isn't an address. Something weird is going to happen.

The argument to atoi is a null-terminated string. Array a does not contain a string, and it isn't null-terminated. If array a doesn't happen to contain a null character (0), then atoi will read past the end of the array. Something weird is going to happen.

What do you want this program to do?
Jan 30 '15 #3

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

Similar topics

3
2968
by: fowlertrainer | last post by:
Hello ! I see these things in many sources, under wxPy: def __init__(self,params,**kw,**args) What are these parameters, and what's the meaning of the double * ? Thanx for any info.
2
3659
by: diadia | last post by:
string s = "hello"; const char *p = s.begin(); cout << p << endl; // print hello s = ""; char *p2= s.begin(); cout << p2 << endl; // print hello why?????
1
1261
by: Dmitry Tkach | last post by:
Hi, everybody! I have been running a 7.3 database for a couple of weeks... and it has grown by more than 20Gig on me within that interval... I have a copy of the original database (I just copied all the files before I started using it), and am trying to find out what exactly it is that grew so much... My understanding is that the files are identified by the oids the objects they belong to...
2
1593
by: arthurzzk | last post by:
<bean id="sesFactoryWeb" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"><ref local="XXXXXX"/></property> <property name="mappingResources"> <list> <value>Unit.hbm.xml</value> <value>UnitConversion.hbm.xml</value> <value>UnitClass.hbm.xml</value> </list> </property> <property...
5
10428
by: bhushanbagul | last post by:
Hi All Please let me know exactly what difference i and g makes in oracle version i.e. when we say oracle 10g or oracle 11i Thanks Bhushan
10
1540
by: CC | last post by:
Hi: I have considerable C and assembly language experience. However, these are mostly on embedded microcontrollers since I moved away from PC programming all the way back in 1988 :-O I wish to accomplish a few PC programming tasks, and am considering to learn Python: 1. Develop a simple GUI program to run on Linux and Windows which can
2
1353
by: dellmacj | last post by:
hi, could someone explain to me in non-tech speak these programs? I'm a novice and C is a bit harder than i thought...how do you write them? 1.an integer is said to be square free if its factors cannot be decomposed into other factors. write a program to print the 1st 10 square free integers starting from 16. 2.a perfect number is a number in which the sum of all the factors is equal to that number. write a program to print the first 4...
10
9493
LazyPrinzez
by: LazyPrinzez | last post by:
Hello! I've just learned Java for about a month and a half. It's our focus for this semester. Now my teacher said that for our project, we are to make useful programs with GUI. She said that games would be okay. The thing is, I don't have any idea what I'm supposed to make in this project. Our deadline for passing program proposal is the end of January, but I still don't know what to make! >.< I have thought of making a memo-calendar that...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.