LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-09-2018, 06:47 AM   #16
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 3,145
Blog Entries: 9

Rep: Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671

Hey, FOUND IT!

It was my fault. Mea culpa, mea culpa, mea maxima culpa!

I added a comment about the preprocessor and forgot to end it with "*/". So the preprocessor directive to include the header files was wrongly taken to be part of the comment.

Just end the comment correctly and those warnings should disappear. Though I don't think they're important anyway.
 
1 members found this post helpful.
Old 12-09-2018, 06:51 AM   #17
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: Currently OpenMandriva. Previously openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 2,879

Original Poster
Rep: Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480
Sorry, I'm an idiot, just spotted the executable it did compile, but thought it didn't - alert.

But anyway, the exit status doesn't seem to work. I'm not sure I've written it correctly.

Quote:
Originally Posted by hazel View Post
Hey, FOUND IT!

It was my fault. Mea culpa, mea culpa, mea maxima culpa!

I added a comment about the preprocessor and forgot to end it with "*/". So the preprocessor directive to include the header files was wrongly taken to be part of the comment.

Just end the comment correctly and those warnings should disappear. Though I don't think they're important anyway.
It's always something simple isn't it?

Thanks again, will do.

Last edited by jsbjsb001; 12-09-2018 at 06:53 AM.
 
Old 12-09-2018, 07:03 AM   #18
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 505

Rep: Reputation: 224Reputation: 224Reputation: 224
Quote:
Originally Posted by hazel View Post
Those are warnings, not errors. I'm not sure what's causing them but they shouldn't stop the compilation from completing. Are there messages that actually contain the word "Error"? Those are the ones you need to look at.
I strongly disagree. Warnings are very often signs of programmer doing something wrong. Understanding and fixing warnings is a valuable learning opportunity, so especially when learning I recommend enabling all warnings and turning them into errors with: gcc -Wall -Werror -std=c11 test.c -o test. Running this actually gives very strong hints as to what the problem in the code is.

An the problem is that a block comment at the beginning of the file is not closed:
Code:
/* Additional note: The C preprocessor is just a global editor. Directives for
the preprocessor always begin with a #.
As a result, #include directive take no effect and you don’t get prototypes for functions you’re using. You can tell this is an issue because the warnings include a phrase ‘implicit declaration’. And implicit declaration of a function is assumed when you use a function without declaring it first.
 
1 members found this post helpful.
Old 12-09-2018, 07:35 AM   #19
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 3,145
Blog Entries: 9

Rep: Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671
Actually when this is fixed, you still get the same warnings about the two internal functions because they are defined after being called by main().

In a very simple program like this, the answer would be simply to put the code for these functions first and then the code for main() at the end. And in fact all the C code I have ever seen lists the main function last. But the correct solution is to put declarations for these functions at the top of the code, just under the #include statements.

As a general rule what mina86 said is correct. A warning means that the compiler found something wrong but used a standard fix for it; unfortunately the result might not be what you intended at all. For example, a mismatch in type between a variable and the value being assigned to it is solved by the compiler retyping the value to fit the variable. But the real problem in most of these cases is that you carelessly used the wrong variable name!

But when you are doing your first build, I think actually getting a compiled version that you can test takes priority. Making the compilation tests too strict is dispiriting.

Last edited by hazel; 12-09-2018 at 07:45 AM.
 
1 members found this post helpful.
Old 12-09-2018, 09:27 AM   #20
hazel
Senior Member
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 3,145
Blog Entries: 9

Rep: Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671Reputation: 1671
Just to go off-topic a fraction, I find the gcc messages extraordinarily opaque. That one the OP got about "implicit declaration" for instance: I've never had that one in any of my programs so I had no idea what it meant. It's only when you have cleared the error that you can say to yourself, "Well, that one means that I did so-and-so." Why doesn't it just say, "Function foo not declared previously"?

An even more cryptic one that had me scratching my head for ages is "Assignment makes X out of Y without a cast". All it means is that you have assigned a value of type Y to a variable of type X. Why can't it say something like "Variable and value have mismatched types"?
 
2 members found this post helpful.
Old 12-09-2018, 08:46 PM   #21
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Debian64 stable, LFS 7.1
Posts: 489

Rep: Reputation: 161Reputation: 161
EDIT: I didn't notice that this thread had more than one page when I replied. (The notes below have already been addressed above.)

Quote:
Originally Posted by jsbjsb001 View Post
So, I've just tried to do my exit status, as well as implementing the suggests so far, but well... I've broken it and now cannot compile it and get a stack of warnings. I moved my variables from being global variables to local variables, which is when my problems started. I was getting errors as well, but I managed to fix them, but I have no idea what I've done wrong here.
Hi jsbjsb001

In your source code, you don't have a terminating */ comment marker before your #include statements (which means your include statements are being recognized as comments).

That's the type of problem that could be easily seen with an IDE. The comment blocks would be indicated in different colors. I would strongly recommend geany to start with.

It looks to me like you're off to a really good start. I'll stay tuned.

Last edited by Andy Alt; 12-09-2018 at 09:59 PM.
 
1 members found this post helpful.
Old 12-09-2018, 10:24 PM   #22
Mill J
Member
 
Registered: Feb 2017
Location: 127.0.0.1 Sweet 127.0.0.1
Distribution: Void, MX, Haiku, Puppy and many others
Posts: 932
Blog Entries: 2

Rep: Reputation: 390Reputation: 390Reputation: 390Reputation: 390
I also highly recommend Geany. It's slim, extremely fast, while staying out of the way and I use it on Windows, Linux, and Mac. The autospacing, auto complete, multiple documents (great for headers) and code highlighting speeds things up drastically and as someone else mentioned it makes it very easy to see mistakes.

I started on C and kind of learned enough C++ to make it easier to write Gui apps. It's very rewarding.

I'd recommend getting familiar with gdb while your code is still small. Geany doesn't support debugging but I found that DDD or just gdb work decent. I could have saved many hours if I would have tackled it sooner.

And yes the million dollar, many days to find bugs are the most simple ones.



Have Fun.
 
1 members found this post helpful.
Old 12-09-2018, 11:58 PM   #23
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: Currently OpenMandriva. Previously openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 2,879

Original Poster
Rep: Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480
Alrighty, I've done a little code cleanup (and fixed a few things - I think) as per Hazel's suggestion to use puts() instead of printf(), but I didn't replace printf() for the statements that use the variables - cuz I don't know if I can or not. I did leave some of the printf() statements there that don't use variables - I just wanted to get the hang of it first.

I checked the exit status and while it reports the following (if I've checked properly), I can't seem to make it fail. This suggests to me that I've not written the right condition, but I'm just not sure what that condition should be. But it's just not clear to me where or really if I'm going wrong there ? Don't know.

Code:
Enter a number and press ENTER, then the same again: 0
0
You entered 0
You entered 0
Less than 100 ;-)
Moved to function value_less_than_100()'
Enter a number and press ENTER, then the same again twice:
0
0
0
You entered 0
You entered 0
You entered 0
0 multiplied by 0 minus 0 is: 0
Less than 50, well this sucks :-(((((
No errors reported - good news!
[james@jamespc devel]$ echo $?
32
I'm thinking that "32" is a positive exit status ?

Also, while I'm not getting the warnings I was getting before, I'm getting one warning complaining about exit(1) - but I still cannot figure out why, I've tried changing the code (like removing the brackets, so it's like just "exit 1;"), but it spits out an error when I do. This is the warning below;

Code:
[james@jamespc devel]$ gcc test.c -o test
test.c: In function ‘main’:
test.c:75:7: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
       exit (1);
       ^
Also, just one more question; while I will be re-reading what I have to date to try and re-enforce the concepts, and while I'm not sure I'm quite ready to move onto file IO just yet; am I right in thinking that, or do you guys think that I should move onto that? Interested to know, feel free to provide any thoughts you may have about that.

I'll have a look at Geany since more than just one person has suggested it - I guess it must be good if that's true.

As usual I've attached my "updated" code for review. Thanks heaps.

James
Attached Files
File Type: txt test.c.txt (4.6 KB, 9 views)
 
Old 12-10-2018, 03:51 AM   #24
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 505

Rep: Reputation: 224Reputation: 224Reputation: 224
Quote:
Originally Posted by Andy Alt View Post
In your source code, you don't have a terminating */ comment marker before your #include statements (which means your include statements are being recognized as comments).

That's the type of problem that could be easily seen with an IDE. The comment blocks would be indicated in different colors.
You don’t need a full blown IDE for that. Any decent editor will do that.

Quote:
Originally Posted by jsbjsb001 View Post
Alrighty, I've done a little code cleanup (and fixed a few things - I think) as per Hazel's suggestion to use puts() instead of printf(), but I didn't replace printf() for the statements that use the variables - cuz I don't know if I can or not. I did leave some of the printf() statements there that don't use variables - I just wanted to get the hang of it first.
If you need to include formatting and thus variables in output use printf. If you’re outputting plain string, use puts (though beware that puts adds new line character at the end).

Quote:
Originally Posted by jsbjsb001 View Post
Code:
$ echo $?
32
I'm thinking that "32" is a positive exit status ?
It’s a positive number, but in Linux anything non-zero means failure. Though looking at your code I don’t see how you’re getting 32.

You should be getting 0. Because there is no way in your code for the exit to execute. Compile your code with gcc -Wall -Werror test.c -o test and the error will be revealed to you.

Quote:
Originally Posted by jsbjsb001 View Post
Also, while I'm not getting the warnings I was getting before, I'm getting one warning complaining about exit(1) - but I still cannot figure out why, I've tried changing the code (like removing the brackets, so it's like just "exit 1;"), but it spits out an error when I do. This is the warning below;

Code:
[james@jamespc devel]$ gcc test.c -o test
test.c: In function ‘main’:
test.c:75:7: warning: incompatible implicit declaration of built-in function ‘exit’ [enabled by default]
       exit (1);
       ^
Run man 3 exit and see synapsis of the function. Specifically, which header file you need to include.

To be honest I don’t see why you bother with exit. Just return from main. You need exit only if you want to terminate the program from within some other function.

Quote:
Originally Posted by jsbjsb001 View Post
Also, just one more question; while I will be re-reading what I have to date to try and re-enforce the concepts, and while I'm not sure I'm quite ready to move onto file IO just yet; am I right in thinking that, or do you guys think that I should move onto that? Interested to know, feel free to provide any thoughts you may have about that.
Your current code isn’t working correctly yet, so you probably should get that in order before you move to next things.
 
2 members found this post helpful.
Old 12-10-2018, 07:10 PM   #25
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: Currently OpenMandriva. Previously openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 2,879

Original Poster
Rep: Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480
Quote:
Originally Posted by mina86 View Post
...
If you need to include formatting and thus variables in output use printf. If you’re outputting plain string, use puts (though beware that puts adds new line character at the end).
Will do, thanks for the tips.


Quote:
It’s a positive number, but in Linux anything non-zero means failure. Though looking at your code I don’t see how you’re getting 32.

You should be getting 0. Because there is no way in your code for the exit to execute. Compile your code with gcc -Wall -Werror test.c -o test and the error will be revealed to you.
Ok, I did what you said and this is what I got:

Code:
[james@jamespc devel]$ gcc -Wall -Werror test.c -o test
test.c: In function ‘main’:
test.c:60:5: error: implicit declaration of function ‘value_less_than_100’ [-Werror=implicit-function-declaration]
     ret = value_less_than_100();
     ^
test.c:65:5: error: implicit declaration of function ‘value_not_less_than_100’ [-Werror=implicit-function-declaration]
     ret = value_not_less_than_100();
     ^
test.c:71:5: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
     if ( c = 0 ) {
     ^
test.c:74:7: error: implicit declaration of function ‘exit’ [-Werror=implicit-function-declaration]
       exit (1);
       ^
test.c:74:7: error: incompatible implicit declaration of built-in function ‘exit’ [-Werror]
test.c:79:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1: all warnings being treated as errors
I'm thinking that based on the above, I have not included stdlib.h (which I didn't), and I have not written it properly - so it doesn't know when it's supposed to do a non-exit status. I don't know what else to say but, as I'm still just way too green with it at this point.

Quote:
Run man 3 exit and see synapsis of the function. Specifically, which header file you need to include.
Thanks for that - didn't realise exit had a man page. I've now added the header in there. I've just read the man page for exit, but while some of it makes sense, I'm not sure I fully understand.

I *think* I get the idea, but I'm just struggling to understand how to apply it. I tried to Google it, but the hits I looked at either tell me what I already know or just make little sense to my dumbass. I couldn't even find any examples to learn from.

Quote:
To be honest I don’t see why you bother with exit. Just return from main. You need exit only if you want to terminate the program from within some other function.
If I knew what I was doing, I'd suspect I'd agree with you - but I want to learn and understand exit status. As I think it's important that I should understand it/get an understanding of it.

Quote:
Your current code isn’t working correctly yet, so you probably should get that in order before you move to next things.
I tend to agree with you, so I'll hold off on file IO for now, and just focus on getting my current code right. Thanks for the advice.

I'll try a few more things and let ya's know how I go. Thanks again for your time.
 
Old 12-10-2018, 08:53 PM   #26
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Debian64 stable, LFS 7.1
Posts: 489

Rep: Reputation: 161Reputation: 161
Quote:
I'm thinking that based on the above, I have not included stdlib.h (which I didn't), and I have not written it properly - so it doesn't know when it's supposed to do a non-exit status. I don't know what else to say but, as I'm still just way too green with it at this point.
You'll want to look up the difference between "function prototypes" and "function definitions", and note the relevance of their locations within the source code.

Quote:
Thanks for that - didn't realise exit had a man page. I've now added the header in there. I've just read the man page for exit, but while some of it makes sense, I'm not sure I fully understand.
That's fine, looks like you got the info mina86 was pointing you toward.

Quote:
If I knew what I was doing, I'd suspect I'd agree with you - but I want to learn and understand exit status. As I think it's important that I should understand it/get an understanding of it.
For the record, you can get an exit status with the return keyword. Because "return" returns control to the calling function, if it's used in main(), then the program exits. When "return" is used in a function that's called from main(), it returns to main(). That's why usually exit() is more useful in functions other than main. Sometimes you don't want to "return" to main, but you want to exit(). Both "return" and "exit" can leave an exit code.
 
1 members found this post helpful.
Old 12-10-2018, 09:01 PM   #27
mina86
Member
 
Registered: Aug 2008
Distribution: Slackware
Posts: 505

Rep: Reputation: 224Reputation: 224Reputation: 224
Quote:
Originally Posted by jsbjsb001 View Post
I'm thinking that based on the above, I have not included stdlib.h (which I didn't), and I have not written it properly - so it doesn't know when it's supposed to do a non-exit status. I don't know what else to say but, as I'm still just way too green with it at this point.
Just keep hacking the code until all the warnings and errors are gone. Feel free to ask if you’re stuck at any of the warnings.

Quote:
Originally Posted by jsbjsb001 View Post
Thanks for that - didn't realise exit had a man page.
Every libc function has a man page. They are all in section 3, i.e. you can access them via man 3 function.

Quote:
Originally Posted by jsbjsb001 View Post
I couldn't even find any examples to learn from.
That’s probably because in vast majority of cases people don’t use exit and simply return from main.

Quote:
Originally Posted by jsbjsb001 View Post
If I knew what I was doing, I'd suspect I'd agree with you - but I want to learn and understand exit status. As I think it's important that I should understand it/get an understanding of it.
Using exit is orthogonal to understanding exit status. Whatever you return from main is your program’s exit status so you don’t need exit at all.

exit is useful if you want to exit from within some other function which you call (indirectly) from main (though some would argue that it’s bad style anyway and should be avoided if possible).

Programs exit status can be interrogated in shell with $?. Zero means success and non-zero means failure. For example:

Code:
$ cat isprime.c 
/* This is purposefully buggy and lacks error checking.
   Fixing the issues is left as exercises to the reader. */

#include <stdlib.h>
#include <stdbool.h>

static bool isprime(const int n) {
	for (int i = 3; i < n; i += 2) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

int main(int argc, char **argv) {
	return !isprime(atoi(argv[1]));
}
$ make isprime
gcc     isprime.c   -o isprime
$ ./isprime 15 && echo 15 is prime
$ ./isprime 11 && echo 11 is prime
11 is prime
 
2 members found this post helpful.
Old 12-10-2018, 09:41 PM   #28
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: Currently OpenMandriva. Previously openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 2,879

Original Poster
Rep: Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480
Thanks for the replies guys.

But, yeah, it's still not working no matter what I seem to try, it just won't work, and I'm still getting the same exit code as before. I've posted the errors (with warnings being treated as errors) below, I'm just not getting it. I've read this and this, and while I think (for the most part) I can understand what it's saying - I still have little to no clue as to what I'm doing wrong. I know I'm doing something wrong/not understanding something, and it just doesn't seem to matter what I read, I'm still no closer to getting it to work.

Here's the outputs and what I've tried:

Code:
[james@jamespc devel]$ gcc -Wall -Werror test.c -o test
test.c: In function ‘main’:
test.c:61:5: error: implicit declaration of function ‘value_less_than_100’ [-Werror=implicit-function-declaration]
     ret = value_less_than_100();
     ^
test.c:66:5: error: implicit declaration of function ‘value_not_less_than_100’ [-Werror=implicit-function-declaration]
     ret = value_not_less_than_100();
     ^
test.c:72:10: error: expected expression before ‘return’
     if ( return = 1 ) {
          ^
test.c:80:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1: all warnings being treated as errors
So I changed it, and:

Code:
[james@jamespc devel]$ gcc -Wall -Werror test.c -o test
test.c: In function ‘main’:
test.c:61:5: error: implicit declaration of function ‘value_less_than_100’ [-Werror=implicit-function-declaration]
     ret = value_less_than_100();
     ^
test.c:66:5: error: implicit declaration of function ‘value_not_less_than_100’ [-Werror=implicit-function-declaration]
     ret = value_not_less_than_100();
     ^
test.c:72:10: error: expected expression before ‘return’
     if ( return = 1 ) {
          ^
test.c: At top level:
test.c:84:1: error: return type defaults to ‘int’ [-Werror=return-type]
 value_less_than_100()
 ^
test.c:119:1: error: return type defaults to ‘int’ [-Werror=return-type]
 value_not_less_than_100()
 ^
test.c: In function ‘main’:
test.c:80:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
cc1: all warnings being treated as errors
I'm thinking the problem is something with this bit of code below:

Code:
 if ( c = 0 ) {
      
      puts("an error has occured - program exiting...");
      exit (1);
      }
      else {
    puts("No errors reported - good news!"); }
I'm sorry guys but it's just not clear one little bit what the problem is to me. Does anyone know where I can see some examples? As the only way I learn is by doing, just reading about just won't give me a complete picture - I could read it 100 times, and still not get the complete picture - unless maybe it's in really, really simple terms. Or I can actually see how it works in code that does work.

As usual I've attached what I've got so far. Thanks.
Attached Files
File Type: txt test.c.txt (4.6 KB, 12 views)

Last edited by jsbjsb001; 12-10-2018 at 09:47 PM. Reason: typo
 
Old 12-10-2018, 10:10 PM   #29
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 755

Rep: Reputation: 144Reputation: 144
Quote:
Originally Posted by jsbjsb001 View Post
Code:
[james@jamespc devel]$ gcc -Wall -Werror test.c -o test
test.c: In function ‘main’:
test.c:61:5: error: implicit declaration of function ‘value_less_than_100’ [-Werror=implicit-function-declaration]
     ret = value_less_than_100();
     ^
If you don't want to move main() to the bottom of the file, put these forward reference lines somewhere above main(). Also note that since this is a C file (not C++), you must use "(void)", not "()".
Code:
int value_less_than_100(void);
int value_not_less_than_100(void);

Quote:
Originally Posted by jsbjsb001 View Post
Code:
test.c:72:10: error: expected expression before ‘return’
     if ( return = 1 ) {
          ^
That line isn't in the file I downloaded. It has two problems. "return" is a keyword. You can't use it as a variable name. Second, you're doing an assignment with "=" when you should doing a comparison with "==".


Quote:
Originally Posted by jsbjsb001 View Post
Code:
test.c: In function ‘main’:
test.c:80:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^
You have to either put a "return" statement at the end of main(), or declare it void. (I think you're allowed to declare it void. Haven't tried that in years.)


Quote:
Originally Posted by jsbjsb001 View Post
Code:
 if ( c = 0 ) {
That's an assignment. Use "==".
 
1 members found this post helpful.
Old 12-10-2018, 10:48 PM   #30
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth? I would say I hope so but I'm not so sure about that... I could just be a figment of your imagination too.
Distribution: Currently OpenMandriva. Previously openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 2,879

Original Poster
Rep: Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480Reputation: 1480
KenJackson, your advice WORKED! I knew I was missing something (well a couple of things actually), so I changed the code as you said, and now it's reporting a zero and not "32" as before. And I'm lot clearer in where I was going wrong now.

But that said, I'll have to read up and practice "assignments", as well as pretty much everything else (well almost).

I've attached the code once again, so ya'll can see exactly what I've done. And I'll try a few things and post an "update".

Here's the results (of both success and failure),

Code:
[james@jamespc devel]$ ./test 
This program uses variables, if statements and functions to display which numbers you have entered and carry out mathematical operations on the numbers entered



Enter a number and press ENTER, then the same again: 7
7
You entered 7
You entered 7
Less than 100 ;-)
Moved to function value_less_than_100()'
Enter a number and press ENTER, then the same again twice:
7
7
7
You entered 7
You entered 7
You entered 7
7 multiplied by 7 minus 7 is: 42
Less than 50, well this sucks :-(((((
No errors reported - good news!
[james@jamespc devel]$ echo $?
0

Code:
[james@jamespc devel]$ ./test 
This program uses variables, if statements and functions to display which numbers you have entered and carry out mathematical operations on the numbers entered



Enter a number and press ENTER, then the same again: 0
0
You entered 0
You entered 0
Less than 100 ;-)
Moved to function value_less_than_100()'
Enter a number and press ENTER, then the same again twice:
0
0
0
You entered 0
You entered 0
You entered 0
0 multiplied by 0 minus 0 is: 0
Less than 50, well this sucks :-(((((
an error has occured - program exiting...
[james@jamespc devel]$ echo $?
1
Thank you so much! THANK YOU, this is excellent!
Attached Files
File Type: txt test.c.txt (4.6 KB, 7 views)
 
  


Reply

Tags
c programming, learning c


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finally decided to try to get libinput to work Timothy Miller Linux - Hardware 3 01-04-2018 08:04 PM
Decided to try Lubuntu 14.04 on my netbook... pcninja Ubuntu 4 04-20-2014 08:18 PM
Finally decided to get serious & learn a302svt LinuxQuestions.org Member Intro 1 07-19-2007 12:27 PM
Decided to try Debian some guidance required ninadb Debian 2 08-20-2004 11:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration