Hi everyone, am currently building a program with VS 6.0 but am having problems with
string coruption, especially with strncpy(),
#include <stdio.h>
#include <string.h>
int main()
{
char prog[200];
int count;
int su2;
char mir[200];
strcpy(prog, "cmd.exe"); // we add cmd.exe to prog
count = strlen(prog); // we measure the length of prog
printf("1.%d\n", count);
su2 = count - 1; // we remove 1 form the count of characters we obtain from prog
printf("2.%d\n", su2); // & store it in su2
strncpy(mir, prog, su2); // we remove 6 characters from prog & store it into mir
printf("3.%s\n", mir);
return 0;
}
<< moderator edit: added [code][/code] tags >>
at ""printf("3.%s\n", mir);"" am supposed to receive "c" but i reveive cmd.ex