P
pkirk25
I've made a small program to demonstrate one problem I'm having fixing
strings in C.
I need to be able to remove HTML mark-ups from text lines.
I create my variable, pass it to my function, verify that the data has
been passed correctly and then cannot get the data back!
If I change the return to some random string literal, it comes back
fine.
All advice appreciated.
#include <stdio.h>
#include <string.h>
char * FixString(char *strIn)
{
char *strMsg = strIn;
char strTmp[40] = "";
char *strReturn = &strTmp;
int i = 0;
int j = strlen(strMsg);
for (i = 0; i <= j; ++i)
{
/* removing the cleanup code for brevity on usenet */
strTmp = strMsg;
}
printf("%s\n", strReturn);
/* Prints out the string perfectly */
return strReturn; /* change to return "All clear" and it works fine
*/
}
int main(void)
{
char *strOut = "This is a line from a web page <br>";
char *strBack = FixString(strOut);
printf("%s\n", strBack); /* Prints garbage - why? */
return 0;
}
strings in C.
I need to be able to remove HTML mark-ups from text lines.
I create my variable, pass it to my function, verify that the data has
been passed correctly and then cannot get the data back!
If I change the return to some random string literal, it comes back
fine.
All advice appreciated.
#include <stdio.h>
#include <string.h>
char * FixString(char *strIn)
{
char *strMsg = strIn;
char strTmp[40] = "";
char *strReturn = &strTmp;
int i = 0;
int j = strlen(strMsg);
for (i = 0; i <= j; ++i)
{
/* removing the cleanup code for brevity on usenet */
strTmp = strMsg;
}
printf("%s\n", strReturn);
/* Prints out the string perfectly */
return strReturn; /* change to return "All clear" and it works fine
*/
}
int main(void)
{
char *strOut = "This is a line from a web page <br>";
char *strBack = FixString(strOut);
printf("%s\n", strBack); /* Prints garbage - why? */
return 0;
}