L
Lily Jost
Hello
Is this the proper forum for this question? If not, will you please
let me know where I should ask it? Thank you! - Lily
…………
1) Version numbers, why I'm doing it this way, books/manuals I've
tried
2) Description of Problem
3) Terminal Session
4) My code (it's not that big - I'm a newbie)
.................... 1) Version numbers, why I'm doing it this way,
books/manuals I've tried
I have been trying hard to figure out how to solve this challenge on
my own. Honest!
I’m running Mac OS X, version 10.6.4. I’m using the editor in XCode
ver 3.2.3, to create my examples. I’m compiling and running the
examples from Terminal version 2.1.1.
I’m using this setup because it’s recommended by the book author of
the book I’m using (as a self-taught student – not taking a class).
I’m using the O’Reilly Nutshell book – Cocoa and Objective-C but THIS
QUESTION is based on material up to chapter 3 and that is C - NOT
OBJECTIVE C (Stevenson gets to Objective C starting in chapter 4). I'm
trying to keep writing samples like he writes the book examples,
because he refers back to these methods and how to use data types in
the next chapters (yes - I have moved forward with chapters 4 and 5).
Being able to work with data types - kinda important!
I can get all of the book examples up through chapter 3 to compile and
run properly on my Mac. I thought it would be good to go beyond just
debugging my typing errors, and see if I could do something every so
slightly different than I was being instructed to do, to work.
Especially since the use of ‘*’ and & is not that clear to me, no
matter how many times I reread those sections of the book. In theory I
understand the difference between a memory address where you store
stuff and the value you store there. I understand what an array is. I
have used these ideas in other languages – but I don’t get how they
work in C, so far.
I also checked two C books out of the library this morning and pawed
through them, reading about dereferencing and looking for similar
examples to the one I based this on in the Nutshell book. I can’t find
one that seems to kind of implicitly accept input from the terminal
line, like he does. Though I don’t think the way I’m inputting or
reading is the problem. (Harbison and Steele C, A Reference Manual and
Kalicharan’s C Programming – Beginners Course)
* * * * 2) Here is my problem * * *
Problem is that I’m trying to accept two numbers input on the Terminal
line (following the program name). I can count the number of entries
properly (all 3 error handling conditions work, plus too many inputs
also gives proper error. Also I have tested with numbers that have
more than one digit).
But… I cannot actually manage to pickup/display the actual numeric
data that the user inputs. I THINK MAYBE I’m displaying memory
addresses, and that maybe I’m not understanding dereferencing
properly. I know I find the use of ‘*’ and ‘&’ confusing. I understand
that the compile warning error is telling me I’m not setting up an
integer array correctly, but I don’t understand how to set it up.
I did try asking for membership to the forum that the O’Reilly author
refers to in his book, 2 days ago. But they have to approve all
membership, and I haven’t gotten anything back from them. I promise
I'm a good usenet citizen. I used to get and give a lot of help in the
perl forum – 10 or more years ago (that makes me feel old).
………………. 3) Here is my Terminal session – Even though I got a warning
error, and clearly it’s trying to tell me something important, I can
still run my example. It just doesn’t do what I want it to. ……….
lily-josts-imac:ch03 davidjost$ gcc
AcceptUserInputTwoNumbersNDDisplayEm.c -o
AcceptUserInputTwoNumbersNDDisplayEm
AcceptUserInputTwoNumbersNDDisplayEm.c: In function ‘main’:
AcceptUserInputTwoNumbersNDDisplayEm.c:41: warning: format ‘%i’
expects type ‘int’, but argument 2 has type ‘int *’
AcceptUserInputTwoNumbersNDDisplayEm.c:42: warning: format ‘%i’
expects type ‘int’, but argument 2 has type ‘int **’
… despite the warning – I go ahead and run it …..
lily-josts-imac:ch03 davidjost$ ./AcceptUserInputTwoNumbersNDDisplayEm
4 5
You entered 2 numbers, and that is correct
The first number you input was 1606417151
Or is this more like it? 1606416872
lily-josts-imac:ch03 davidjost$
………………. 4) Here is my Code ……
/*
* AcceptUserInputTwoNumbersNDDisplayEm.c *
* Accept two numbers input by the user on the terminal line
* Display the first number the user typed in
*
*/
#include <stdio.h>
main ( int inputCount, int* inputValues[]) {
// don't count the program name as a value
// I THINK that 'inputCount' from page 69
// only occurs here and as an argument to main
// unclear how inputCount ever picks up a value
int numericCount = 0;
numericCount = (inputCount -1);
// tell the user how many numbers she entered
if (numericCount > 0) {
if (numericCount == 2) {
printf("You entered %i numbers, and that is correct \n",
numericCount);
} else {
printf("You entered the wrong number of input values. Enter 2
values. You entered %i \n", numericCount);
}
} else {
printf("You didn't enter any numbers\n");
// exit (1);
}
// the first instance of the array is 0, but that would be program
name
printf("The first number you input was %i \n", inputValues[1]);
printf("Or is this more like it? %i \n", &inputValues[1]);
}
Is this the proper forum for this question? If not, will you please
let me know where I should ask it? Thank you! - Lily
…………
1) Version numbers, why I'm doing it this way, books/manuals I've
tried
2) Description of Problem
3) Terminal Session
4) My code (it's not that big - I'm a newbie)
.................... 1) Version numbers, why I'm doing it this way,
books/manuals I've tried
I have been trying hard to figure out how to solve this challenge on
my own. Honest!
I’m running Mac OS X, version 10.6.4. I’m using the editor in XCode
ver 3.2.3, to create my examples. I’m compiling and running the
examples from Terminal version 2.1.1.
I’m using this setup because it’s recommended by the book author of
the book I’m using (as a self-taught student – not taking a class).
I’m using the O’Reilly Nutshell book – Cocoa and Objective-C but THIS
QUESTION is based on material up to chapter 3 and that is C - NOT
OBJECTIVE C (Stevenson gets to Objective C starting in chapter 4). I'm
trying to keep writing samples like he writes the book examples,
because he refers back to these methods and how to use data types in
the next chapters (yes - I have moved forward with chapters 4 and 5).
Being able to work with data types - kinda important!
I can get all of the book examples up through chapter 3 to compile and
run properly on my Mac. I thought it would be good to go beyond just
debugging my typing errors, and see if I could do something every so
slightly different than I was being instructed to do, to work.
Especially since the use of ‘*’ and & is not that clear to me, no
matter how many times I reread those sections of the book. In theory I
understand the difference between a memory address where you store
stuff and the value you store there. I understand what an array is. I
have used these ideas in other languages – but I don’t get how they
work in C, so far.
I also checked two C books out of the library this morning and pawed
through them, reading about dereferencing and looking for similar
examples to the one I based this on in the Nutshell book. I can’t find
one that seems to kind of implicitly accept input from the terminal
line, like he does. Though I don’t think the way I’m inputting or
reading is the problem. (Harbison and Steele C, A Reference Manual and
Kalicharan’s C Programming – Beginners Course)
* * * * 2) Here is my problem * * *
Problem is that I’m trying to accept two numbers input on the Terminal
line (following the program name). I can count the number of entries
properly (all 3 error handling conditions work, plus too many inputs
also gives proper error. Also I have tested with numbers that have
more than one digit).
But… I cannot actually manage to pickup/display the actual numeric
data that the user inputs. I THINK MAYBE I’m displaying memory
addresses, and that maybe I’m not understanding dereferencing
properly. I know I find the use of ‘*’ and ‘&’ confusing. I understand
that the compile warning error is telling me I’m not setting up an
integer array correctly, but I don’t understand how to set it up.
I did try asking for membership to the forum that the O’Reilly author
refers to in his book, 2 days ago. But they have to approve all
membership, and I haven’t gotten anything back from them. I promise
I'm a good usenet citizen. I used to get and give a lot of help in the
perl forum – 10 or more years ago (that makes me feel old).
………………. 3) Here is my Terminal session – Even though I got a warning
error, and clearly it’s trying to tell me something important, I can
still run my example. It just doesn’t do what I want it to. ……….
lily-josts-imac:ch03 davidjost$ gcc
AcceptUserInputTwoNumbersNDDisplayEm.c -o
AcceptUserInputTwoNumbersNDDisplayEm
AcceptUserInputTwoNumbersNDDisplayEm.c: In function ‘main’:
AcceptUserInputTwoNumbersNDDisplayEm.c:41: warning: format ‘%i’
expects type ‘int’, but argument 2 has type ‘int *’
AcceptUserInputTwoNumbersNDDisplayEm.c:42: warning: format ‘%i’
expects type ‘int’, but argument 2 has type ‘int **’
… despite the warning – I go ahead and run it …..
lily-josts-imac:ch03 davidjost$ ./AcceptUserInputTwoNumbersNDDisplayEm
4 5
You entered 2 numbers, and that is correct
The first number you input was 1606417151
Or is this more like it? 1606416872
lily-josts-imac:ch03 davidjost$
………………. 4) Here is my Code ……
/*
* AcceptUserInputTwoNumbersNDDisplayEm.c *
* Accept two numbers input by the user on the terminal line
* Display the first number the user typed in
*
*/
#include <stdio.h>
main ( int inputCount, int* inputValues[]) {
// don't count the program name as a value
// I THINK that 'inputCount' from page 69
// only occurs here and as an argument to main
// unclear how inputCount ever picks up a value
int numericCount = 0;
numericCount = (inputCount -1);
// tell the user how many numbers she entered
if (numericCount > 0) {
if (numericCount == 2) {
printf("You entered %i numbers, and that is correct \n",
numericCount);
} else {
printf("You entered the wrong number of input values. Enter 2
values. You entered %i \n", numericCount);
}
} else {
printf("You didn't enter any numbers\n");
// exit (1);
}
// the first instance of the array is 0, but that would be program
name
printf("The first number you input was %i \n", inputValues[1]);
printf("Or is this more like it? %i \n", &inputValues[1]);
}