* Problem with "chars"
@ 2002-07-17 9:08 xlp
2002-07-17 13:30 ` Jason L. Shiffer
0 siblings, 1 reply; 3+ messages in thread
From: xlp @ 2002-07-17 9:08 UTC (permalink / raw)
To: linux-c-programming
Hi C people, first of all, I'd like to thank you this mailing list and kernel.org project to give us a place where C programmers feel free to ask their questions and the support is excellent.
I dont understand what's the way I should handle 'chars' on C.
I need to code a C function that returns a char, I want to do this:
char foo();
main(){
char bar*;
bar=foo();
}
How should i declare the 'char' inside foo()?
How should i 'return' the char inside foo()?
How can i understand "chars" and pointers to chars?, I have a C books, but I dont get it, because ALL THE EXAMPLES are with chars like char foo[20], that is the easy way!, I want to handle char without a specific length!.
bye.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Problem with "chars"
2002-07-17 9:08 Problem with "chars" xlp
@ 2002-07-17 13:30 ` Jason L. Shiffer
2002-07-17 14:19 ` Elias Athanasopoulos
0 siblings, 1 reply; 3+ messages in thread
From: Jason L. Shiffer @ 2002-07-17 13:30 UTC (permalink / raw)
To: linux-c-programming
On Wed, Jul 17, 2002 at 04:08:16AM -0500, xlp wrote:
> I dont understand what's the way I should handle 'chars' on C.
> I need to code a C function that returns a char, I want to do this:
> char foo();
> main(){
> char bar*;
> bar=foo();
> }
Firstly if you are just going to return a char ie. some value between
-128 & 127, then the above definition is incorrect:
char bar*; defines a char pointer most commenly known as a string;
char bar; defines a char
> How should i declare the 'char' inside foo()?
the same as above eg,
char foo(void){
char x = 'a';
return x;
}
> How should i 'return' the char inside foo()?
see the previous example.
> How can i understand "chars" and pointers to chars?, I have a C books, but I dont get it, because ALL THE EXAMPLES are with chars like char foo[20], that is the easy way!, I want to handle char without a specific length!.
The best book that I know of for this is "Expert C Programming (Deep C
Secrets) ISBN:0-13-177429-8. And don't let the name scare it is a great
book that will take you pretty much from entry level programming to
advanced topics.
As a short introduction you can think about pointers like this:
char a = 'b'; //the symbol a represents the VALUE b
char *b = &a; //the symbol b represents the MEMORY ADDRESS of the
//symbol a;
it is a little simplified but I hope that it helps.
Jason
>
> bye.
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Problem with "chars"
2002-07-17 13:30 ` Jason L. Shiffer
@ 2002-07-17 14:19 ` Elias Athanasopoulos
0 siblings, 0 replies; 3+ messages in thread
From: Elias Athanasopoulos @ 2002-07-17 14:19 UTC (permalink / raw)
To: Jason L. Shiffer; +Cc: linux-c-programming, xlp
On Wed, Jul 17, 2002 at 09:30:41AM -0400, Jason L. Shiffer wrote:
> On Wed, Jul 17, 2002 at 04:08:16AM -0500, xlp wrote:
> > I dont understand what's the way I should handle 'chars' on C.
> > I need to code a C function that returns a char, I want to do this:
> > char foo();
> > main(){
> > char bar*;
> > bar=foo();
> > }
>
> Firstly if you are just going to return a char ie. some value between
> -128 & 127, then the above definition is incorrect:
> char bar*; defines a char pointer most commenly known as a string;
This defines nothing. It produces a syntax error.
Both, you mean "char *bar;".
Elias
--
http://gnewtellium.sourceforge.net MP3 is not a crime.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-07-17 14:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-17 9:08 Problem with "chars" xlp
2002-07-17 13:30 ` Jason L. Shiffer
2002-07-17 14:19 ` Elias Athanasopoulos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).