How can I pass a string to a function??
How can I pass a string to a function??
---Programming is like roaming, you never know where you'll end at------
If 'here' is pronounced as 'hear', why 'there' isnt pronounced as 'dear'??
[email protected]
void myfun( char * stringy );
...
char buf[BUFSIZ];
myfun( buf );
Quzah.
Hope is the first step on the road to disappointment.
I suppose the real answer is you can't, you have to pass a pointer to the string, like in the example given.Originally posted by Paninaro
How can I pass a string to a function??
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
A simple program to check whether the first or last characters of a string are uppercase...Code:#include <ctype.h> #include <stdio.h> #define TRUE 1 #define FALSE 0 int StringStartsWithUpper (char *); int StringEndsWithUpper (char *); char * myString = "This is the sample string"; int main (void) { printf ("%s\n", myString); // Pass the string to printf if (StringStartsWithUpper (myString)) { // Pass the string to this function printf ("Starts with an upper case letter.\n"); } else { printf ("Doesn't start with an upper case letter.\n"); } if (StringEndsWithUpper (myString)) { // Pass the string to function printf ("Ends with an upper case letter.\n"); } else { printf ("Doesn't end with an upper case letter.\n"); } return 0; } int StringStartsWithUpper (char * checkMe) { return isupper(checkMe[0]); // Pass a char to isUpper() } int StringEndsWithUpper (char * checkMe) { int length = strlen (checkMe); // Pass the string to strlen. Returns the length of the string. return isupper (checkMe [length - 1]); // Pass a char to isUpper() }
Callou collei we'll code the way
Of prime numbers and pings!