Invalid string
#1

Hi, what's the problem of the code below? I'm trying to make a dialog that shows injuries in DIALOG_STYLE_TABLIST_HEADERS.

Код:
new injuries[1000], string[64];
		
format(string, sizeof(string), "Weapon\tBody Part\tTimes Injured\n\");
I get these errors:
Код:
(913) : error 037: invalid string (possibly non-terminated string)
(913) : error 017: undefined symbol "Weapon"
(913) : error 029: invalid expression, assumed zero
(913) : fatal error 107: too many error messages on one line
Reply
#2

Try this

Код:
new injuries[1000], string[64];
		
format(string, sizeof(string), "Weapon\tBody Part\tTimes Injured\n");
Reply
#3

No need to use format for that:

Код:
new injuries[1000], string[64] = "Weapon\tBody Part\tTimes Injured\n\\";
The problem was because you have \", which is an escaped " (So you can have it inside of a string without cutting it off.

You have to escape \ if you want to use it (I did in my code)
Reply
#4

Thanks to both of you.

By the way Stinged, why can't I sometimes set strings like this, but I need to use format? Sometimes it just doesn't let me and gives me errors, format is the only way in this case. I've been always wondering why is it like this.
Reply
#5

Quote:
Originally Posted by GoldenLion
Посмотреть сообщение
By the way Stinged, why can't I sometimes set strings like this, but I need to use format? Sometimes it just doesn't let me and gives me errors, format is the only way in this case. I've been always wondering why is it like this.
If the string was used in something like strcat, strins, format, etc... it can't be set like this.

By the way, if you want to set a string like that (And you can't do the way I did), you shouldn't use format.
Format should only be used when you want to replace specifiers (%i etc) with values.

What you can do is this:
Код:
string[0] = 0;
strcat(string, new string here);
Or you can use this strcpy macro.
Код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)

strcpy(string, new string here);
Reply
#6

Quote:
Originally Posted by Stinged
Посмотреть сообщение
If the string was used in something like strcat, strins, format, etc... it can't be set like this.

By the way, if you want to set a string like that (And you can't do the way I did), you shouldn't use format.
Format should only be used when you want to replace specifiers (%i etc) with values.

What you can do is this:
Код:
string[0] = 0;
strcat(string, new string here);
Or you can use this strcpy macro.
Код:
#define strcpy(%0,%1) strcat((%0[0] = '\0', %0), %1)

strcpy(string, new string here);
Alright, thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)