main()
{
int num;
while(..)
{
num=atoi(str+x)
if(num!=0)
{
....
....
}
else
{
printf("num = %d",num);
}
}
I am not able to access the value of num in the else block. It prints
zero. I am very new to C and as far as I know, num should be accessed
in the else block also as it is declared in the main block which is
actually is the parent block and I guess at runtime, the parent block
is checked for a variable value if that variable is not decalred in
that block.
regards,
vz. 7 1182 Ta***********@yahoo.com scribbled the following: main() { int num; while(..) { num=atoi(str+x) if(num!=0) { ... ... } else { printf("num = %d",num); } }
I am not able to access the value of num in the else block. It prints zero. I am very new to C and as far as I know, num should be accessed in the else block also as it is declared in the main block which is actually is the parent block and I guess at runtime, the parent block is checked for a variable value if that variable is not decalred in that block.
I think the problem is in either the .. part, the ... part or the other
.... part.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Show me a good mouser and I'll show you a cat with bad breath."
- Garfield
Joona I Palaste <pa*****@cc.helsinki.fi> scribbled the following: Ta***********@yahoo.com scribbled the following: main() { int num; while(..) { num=atoi(str+x) if(num!=0) { ... ... } else { printf("num = %d",num); } }
I am not able to access the value of num in the else block. It prints zero. I am very new to C and as far as I know, num should be accessed in the else block also as it is declared in the main block which is actually is the parent block and I guess at runtime, the parent block is checked for a variable value if that variable is not decalred in that block.
I think the problem is in either the .. part, the ... part or the other ... part.
Silly me! I should learn to read code.
Your problem is that your code always displays zero in the else part?
That's really your problem?
Well, your elese part only ever gets executed in the first place if
num is zero. What do you expect it to display?
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"Keep shooting, sooner or later you're bound to hit something."
- Misfire Ta***********@yahoo.com wrote on 03/01/05 : main() { int num; while(..) { num=atoi(str+x)
How are defined an initialized 'str' and 'x'.
if(num!=0) { ... ... } else { printf("num = %d",num); } I am not able to access the value of num in the else block.
What do you meant ? Compile error?
It prints zero.
So what ? It could be an error with atoi(). What is the parameter you
passed to atoi() ? How is it a valid string representing a decimal
value ?
--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html
"C is a sharp tool" Ta***********@yahoo.com wrote: main() { int num; while(..) { num=atoi(str+x) if(num!=0) { ... ... } else { printf("num = %d",num); } }
I am not able to access the value of num in the else block. It prints zero. ...
Of course, it prints zero. You wrote the code so that the control is
passed to 'else' branch if and only if 'num' is zero. No surprisingly,
the code in the 'else' branch prints zero, as it should.
Maybe you should explain what you are trying to implement first.
--
Best regards,
Andrey Tarasevich
<Ta***********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com... main() { int num; while(..) { num=atoi(str+x) if(num!=0) {
/* this block is executed if num is not zero */
... ... } else {
/* this block is executed if num is zero */
printf("num = %d",num); } }
I am not able to access the value of num in the else block.
Yes, you are.
It prints zero.
Well, of course, because the value *is* zero. Zero is a value.
I am very new to C
I can tell. :-)
and as far as I know, num should be accessed in the else block
It is.
also as it is declared in the main block which is actually is the parent block and I guess at runtime, the parent block is checked for a variable value if that variable is not decalred in that block.
Right.
Word of advice: It's better to post a complete, compilable program,
rather than the incomplete code with syntax errors as you did.
-Mike
<Ta***********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com... main() { int num; while(..) { num=atoi(str+x) if(num!=0) { ... ... } else { printf("num = %d",num); } }
hmm....... Whtz da meaning of else here? Is it the same what the language
says or is it something ELSE U want.... "else" here means when num is ZERO.
So, always zero... so far, so good!
-Neo
I am not able to access the value of num in the else block. It prints zero. I am very new to C and as far as I know, num should be accessed in the else block also as it is declared in the main block which is actually is the parent block and I guess at runtime, the parent block is checked for a variable value if that variable is not decalred in that block.
regards, vz.
Exactly. How silly me, I should store the previous non-zero value of
num first. Thanks a lot to all.
regards,
vz. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alexander Mahr |
last post by:
Dear Newsgroup,
I'm somehow confused with the usage of the static keyword.
I can see two function of the keyword static in conjunction with a data
member of a class.
1. The data member...
|
by: Sandy |
last post by:
Hello!
Help!!!!
I have ten zillion books that attempt to describe the
difference between ByVal and ByRef and none of them are
clear to me. I have gathered that ByVal makes a copy and
ByRef...
|
by: Lauren Wilson |
last post by:
Ok I have searched the MS website for info on this. I am totally
confused.
If I want to deploy an Access 2003 app and allow my users to run it
using Access 2003 Runtime, where do I get the...
|
by: Lauren Wilson |
last post by:
The more I look at the issue of digital certification for our Access
app, the more confused I get. The SelfCert feature that allegedly
installed with Office 2003 does not work. The entry is on my...
|
by: Marvin |
last post by:
Hi:
I have been programming with OOP and C++ for over 10 years but I am new
to javascript. I am very confused about one aspect and would appreciate
it if someone could explain the differences...
|
by: redefined.horizons |
last post by:
I've been reading about Python Classes, and I'm a little confused about
how Python stores the state of an object. I was hoping for some help.
I realize that you can't create an empty place holder...
|
by: Lalatendu Das |
last post by:
I have seen a header file in which one structure is defined with
extern declaration in a header file and declared one variable of that
structure in one C-file. The code goes as mentioned below . I...
|
by: Adam Olsen |
last post by:
It seems a common opinion that global access is much slower than local
variable access. However, my benchmarks show a relatively small
difference:
../python -m timeit -r 10 -v -s 'x = * 10000...
|
by: mattmao |
last post by:
I am moving onto the tough part in learning C:(
First, about the declaration of a user defined structure:
I found this syntax in my lecture notes:
struct userinfo
{
char username;
...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
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...
| |