Brandito
May 5th, 2001, 03:01 PM
I've been working on a project in C and I have written this short, some what crappy, function to make it a CGI for the web. My problem is that I am having trouble making differently variables "work" together.
Here is my function with comments on the Problem Parts:
-------------------
#include <stdio.h>
#include <string.h>
char *myValue(char *logPw, int LorP)
{
char * mainString; // = (char * ) malloc (100);
char * loc = 0;
int index_numb = 0;
int LenOfMain;
mainString = "Login=Brandon&Paswd=12345"; // &=14:len=26
LenOfMain = len(mainString);
loc = strstr(mainString, "&");
if (loc == NULL)
printf("Warning: Bad Post!\n");
else
{
if (LorP == 1) // get login name
{
index_numb = 7;
do
{ strcat(logPw, mainString[index_numb]); //is this wrong?
index_numb++;
}while (index_numb != loc); //problem with pointer-int compare
printf("\n\nString: %s \n Login: %s\n", mainString, logPw);
}
else // get password
{
index_numb = (7 + loc);
do
{ strcat(logPw, mainString[index_numb]); //is this wrong?
index_numb++;
}while (index_numb != LenOfMain); //problem with pointer-int compare
printf("\n\nString: %s \n Password: %s\n", mainString, logPw);
}
}
return logPw;
}
Here is my function with comments on the Problem Parts:
-------------------
#include <stdio.h>
#include <string.h>
char *myValue(char *logPw, int LorP)
{
char * mainString; // = (char * ) malloc (100);
char * loc = 0;
int index_numb = 0;
int LenOfMain;
mainString = "Login=Brandon&Paswd=12345"; // &=14:len=26
LenOfMain = len(mainString);
loc = strstr(mainString, "&");
if (loc == NULL)
printf("Warning: Bad Post!\n");
else
{
if (LorP == 1) // get login name
{
index_numb = 7;
do
{ strcat(logPw, mainString[index_numb]); //is this wrong?
index_numb++;
}while (index_numb != loc); //problem with pointer-int compare
printf("\n\nString: %s \n Login: %s\n", mainString, logPw);
}
else // get password
{
index_numb = (7 + loc);
do
{ strcat(logPw, mainString[index_numb]); //is this wrong?
index_numb++;
}while (index_numb != LenOfMain); //problem with pointer-int compare
printf("\n\nString: %s \n Password: %s\n", mainString, logPw);
}
}
return logPw;
}