c - I get the error message:Expression: (L “String is not null terminated” & & 0) -


when run program,i error message.i don't konw how correct it.may help?

char dir[1024]="c:\\users\\username\desktop\\new folder\\pauli\\t3"; void check_dir(char *dir) { int i; = 0; while (dir[i] != '\0') {     if (dir[i] == '/')         dir[i] = '\\';     i++; } strcat_s(dir, sizeof(dir),"\\"); } 

sizeof(dir) doesn't expect here. dir char * inside function, gives size of pointer (*). option pass size of array check_dir() function, too:

void check_dir(char *dir, size_t bufsize) {     [...]     strcat_s(dir, bufsize, "\\"); } 

(*) in scope dir declared char dir[1024], sizeof(dir) will give expected result.

edit: on side note, check_dir() misnomer here, doesn't check tries normalize string windows path backslashes. call e.g. win32_normalize_path() or that. called check_<foo>() should return (e.g. int) containing result of check.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -