Strings??
Strings??
How would I go about declaring strings in the PSPSDK? I've tried:
string blah;
but I get:
main.c:27: error: syntax error before 'blah'
main.c:27: warning: type defaults to 'int' in declaration of 'blah'
in the compiler. Is there an include file I need to recognize or is there a special type I need to use?
One more. How would I use strings in a printf()?
With integers it's like:
printf("%i", blahint);
so would it be:
printf("%s", blahstring);
?
Much appreciated!
string blah;
but I get:
main.c:27: error: syntax error before 'blah'
main.c:27: warning: type defaults to 'int' in declaration of 'blah'
in the compiler. Is there an include file I need to recognize or is there a special type I need to use?
One more. How would I use strings in a printf()?
With integers it's like:
printf("%i", blahint);
so would it be:
printf("%s", blahstring);
?
Much appreciated!
You might want to brush up on your basic C skills...
You're after a character array.
Your formatting for the printf is correct. Note that your character array can also go in place of the formatting string.
You're after a character array.
Code: Select all
char mystring[num];
Re: Strings??
in C, "string" as a type doesn't exist :Dremth wrote:How would I go about declaring strings in the PSPSDK? I've tried:
string blah;
but I get:
main.c:27: error: syntax error before 'blah'
main.c:27: warning: type defaults to 'int' in declaration of 'blah'
in the compiler. Is there an include file I need to recognize or is there a special type I need to use?
One more. How would I use strings in a printf()?
With integers it's like:
printf("%i", blahint);
so would it be:
printf("%s", blahstring);
?
Much appreciated!
Code: Select all
char blah[] = "....";
...
printf("%s\n", blah);
Code: Select all
#include <string>
#include <iostream>
std::string blah;
...
std::cout << blah << std::endl;
in C :Dremth wrote:I knew that I could use the char blah[]; to do a string like thing but I wanted a string array. Like string blah[];. Would I just do char blah[][];? Just do a double demension array?
Code: Select all
char str1[] = "...";
char str3[] = "...";
...
char *strarr[] = { str1, "blahblah", str3, ... };
printf("%s\n", strarr[1]) // prints "blahblah"
Please bear in mind :
int arr[2][3] : 2 arrays of 3 ints
int arr[][3] : N arrays of 3 ints
int arr[2][] : 2 arrays of N ints --> SYNTAX ERROR !
Note that :
char *arr[2] means an array of 2 POINTERS on c strings
This is normal, you don't seem to know either C or C++
please read a C language tutorial and you will know what you can do or not.
Because it is a non-sense to write : blah[] = "ABC." since it must be a declaration of new variable;
the only way to use [] in a expression is to access an element of the array, so :
char blah[] = "ABC"; // blah is a CONSTANT string being seen as an array of char.
printf("%c\n", blah[1]); ------> displays a B on screen.
please read a C language tutorial and you will know what you can do or not.
Because it is a non-sense to write : blah[] = "ABC." since it must be a declaration of new variable;
the only way to use [] in a expression is to access an element of the array, so :
char blah[] = "ABC"; // blah is a CONSTANT string being seen as an array of char.
printf("%c\n", blah[1]); ------> displays a B on screen.