#STUDENT RESPONSE ANI3-B
11 messages in this thread
>>>Jerry>>>
Following is the program I wrote in an attempt to do the assignment.
I get an error message that reads "Printf – too many parameters, after I am
prompted for the first and last names. Jerry, I am really a beginner at this
–
HELP, please.
Hi. The problem is that printf() needs the format used which is
printf("<prompts and variable types>",<variables>);
We went over this… that %d stands for integers, %s is for strings, etc.
You have no "" here either. So, here's what you had:
printf(fname,bsize);
Qtext("Press to continue…");
unprintf();
And it should be:
printf("%s,%s",fname,bsize);
Qtext("Press to continue…");
unprintf();
The same goes for the other printf() statement. The quotes with %vars tell
POCO how the variables should be printed, regardless of their values, and
then the variables that follow fill those positions in the quotes.
<<<Jerry<<<
Hi Jerry,
I tried modifying my program as you suggested, to:
//..Begining of program..
main()
{
char fname[]="Jack";
char lname[]="Winberg";
char say[]="What is your first name?";
char say2[]="What is your last name?";
int bsize=sizeof(fname);
int bsize2=sizeof(lname);
Qstring(fname,bsize, say);
Qtext("Press to continue…");
Qstring(lname,bsize2,say2);
Qtext(Press to continue…");
printf("%s,%s",fname,bsize);
Qtext("Press to continue…");
unprintf();
printf("%s,%s",lname,bsize2);
Qtext("Press to continue…");
unprintf();
}
//..Program ends..
I now get the error message "Error, near line 18, strings cannot span lines
without continuation (\). That has usually meant an error, but I cannot spot
it. Help, please.
Also a few more general questions – I get the need for the formatting sections
in printf(), but the use of quotes ("") confuses me. I thought that was used
to denote string literals.
In addition, I find the POCO manual hard to comprehend. Can you recommend any
other reference that may be somewhat more clear to a beginner. I have some
books on QuickC, but fear that the syntax may be a very different animal than
that used in POCO. Any suggestions?
Thanks, as usual….Jack.
>>>Jerry>>>
Hello Jack. You'll find that little typos like this are deadly! 🙂
main()
{
char fname[]="Jack";
char lname[]="Winberg";
char say[]="What is your first name?";
char say2[]="What is your last name?";
int bsize=sizeof(fname);
int bsize2=sizeof(lname);
Qstring(fname,bsize, say);
Qtext("Press to continue…");
Qstring(lname,bsize2,say2);
Qtext(Press to continue…"); <—where's the " before Press?
printf("%s,%s",fname,bsize);
Qtext("Press to continue…");
unprintf();
printf("%s,%s",lname,bsize2);
Qtext("Press to continue…");
unprintf();
}
Try it again now.
<<<Jerry<<<
Hi Dave,
Ouch! Well, I corrected the missing quote, but now get the error message
"parameter with invalid value near line 21 – printf() statement. ?????? More
help, please, I can't spot any more typo's, but then I couldn't find the first
one.
Latest version:
main()
{
char fname[]="Jack";
char lname[]="Winberg";
char say[]="What is your first name?";
char say2[]="What is your last name?";
int bsize=sizeof(fname);
int bsize2=sizeof(lname);
Qstring(fname,bsize, say);
Qtext("Press to continue…");
Qstring(lname,bsize2,say2);
Qtext("Press to continue…");
printf("%s,%s",fname,bsize);
Qtext("Press to continue…");
unprintf();
printf("%s,%s",lname,bsize2);
Qtext("Press to continue…");
unprintf();
}
Jack
>>>Jerry>>>
Don't feel bad, this one escaped me too. And it's so obvious now. 🙂
I've noted up the declaration problems, the bad designators in the printf()
statements and in remarks suggested a course of action. Try it.
main()
{
char fname[]="Jack";
char lname[]="Winberg";
char say[]="What is your first name?";
char say2[]="What is your last name?";
int bsize=sizeof(fname); <—- this is an integer, right?
int bsize2=sizeof(lname); <— this is an integer, right? look below
Qstring(fname,bsize, say);
Qtext("Press to continue…");
Qstring(lname,bsize2,say2);
Qtext("Press to continue…");
printf("%s,%s",fname,bsize); <—- we have %s for an integer! ow!
Qtext("Press to continue…");
unprintf();
// the above should be:
// printf("%s is %d characters long.",fname,bsize);
// Qtext("Press to continue…");
// unprintf();
printf("%s,%s",lname,bsize2); <— we have %s for an integer! ow!
Qtext("Press to continue…");
unprintf();
// the above should be:
// printf("%s is %d characters long.",lname,bsize2)
// Qtext("Press to continue…");
// unprintf();
}
<<<Jerry<<<
Hi Jerry,
Thanks for your help. I entered the program as suggested, and it all works
just dandy, EXCEPT that sizeof() returns one more character than in the names.
I am using the form char fname{}=X, but still get the wrong count. Here is the
latest revision:
main()
{
char fname[]="Jack";
char lname[]="Winberg";
char say[]="What is your first name?";
char say2[]="What is your last name?";
int bsize=sizeof(fname);
int bsize2=sizeof(lname);
Qstring(fname,bsize, say);
Qtext("Press to continue…");
Qstring(lname,bsize2,say2);
Qtext("Press to continue…");
printf("%s is %d characters long",fname,bsize);
Qtext("Press to continue…");
unprintf();
printf("%s is %d characters long",lname,bsize2);
Qtext("Press to continue…");
unprintf();
}
Do we persist now?
Jack
>>>Jerry>>>
Thanks for your help. I entered the program as suggested, and it all works
just dandy, EXCEPT that sizeof() returns one more character than in the names.
Do we persist now?
Jack, don't take this the wrong way but you've got to read the telecourses
more carefully. This was explained in the course notes. The size of the
char is defined as whatever is in quotes PLUS the end-of-string character.
If you need to get an exact number, use something like bsize-1 (instead of
bsize) in the printf() statement.
I know it's a lot to remember at first, so don't feel discouraged. You're
making good progress here.
<<<Jerry<<<
Jerry,
We seem to have a conflict. Your telecourse notes stated: "Hint: you will
probably have to use the char fname{}="x" format rather than the char fname{x}
format to get sizeof() to report back your first and last name lengths
correctly". I used the suggested format, but now you seem to have reversed
course. Can you help me with the source of my misunderstanding? Thanks.
Jack
Jack
>>>Jerry>>>
We seem to have a conflict. Your telecourse notes stated: "Hint: you will
probably have to use the char fname{}="x" format rather than the char fname{x}
format to get sizeof() to report back your first and last name lengths
correctly". I used the suggested format, but now you seem to have reversed
course. Can you help me with the source of my misunderstanding? Thanks.
If you use the char fname[x] format, Jack, the sizeof() function becomes the
size of the x value, which can be anything. If you use char fname[]="x"
format though where x _is_ your name, sizeof() find the length of your name.
To rephrase more clearly, the char fname[x] format demands you put the
actual size in to begin with whereas the char fname[]="x" format figures out
the size if should be. If your name was supercalafrajalisticexpialadocious,
it would be pain to have count out the characters using char fname[x]
format, but a piece of cake with the char fname[]="supercala…." format.
The course notes did state the _any_ string is always the size of itself
plus one for the end-of-string designator.
<<<Jerry<<<
>>>Jerry>>>
Also a few more general questions – I get the need for the formatting
sections in printf(), but the use of quotes ("") confuses me. I thought that
was used to denote string literals.
The printf() function is a format function. It can be passed most variable
types. "" are used for its format, not for variable properties. The format
is:
printf("prompt with variable placement designators",variables list);
and it has to be in that order. So if we have an integer variable holding a
value of 1, and a string variable holding a value of "Jack" and we want to
have the status line read:
Jack has 1 more program working.
then we would use something like:
int intval=1;
char strval[]="Jack";
printf("%s has %d more program working.",strval,intval);
The quotes here have nothing to do with "strings", they specify the prompting
contents and the placements of variable values in those contents.
<<<Jerry<<<
>>>Jerry>>>
In addition, I find the POCO manual hard to comprehend. Can you recommend any
other reference that may be somewhat more clear to a beginner. I have some
books on QuickC, but fear that the syntax may be a very different animal than
that used in POCO. Any suggestions?
The POCO manual does take some getting used to. It's nothing more than a
dictionary of POCO functions and a short list of those functions from the
C-langauge which are permitted. If you have QuickC (Microsoft), there was a
manual included with that product called "C for Yourself" which is very
helpful. The syntax between C and POCO is the same. POCO is a subset of C in
addition to its own functions. Any book you find helpful with C will help
with POCO. If you have an older version of QuickC which did not include "C
for Yourself", you can still use the other manuals to look up the
"additional C syntax" in our POCO routines as we plow through them.
<<<Jerry<<<