Hi all, i'm trying to make a little program that with a function you can read a file, and get a string (in this case "pStrTrama") fill with the file content. What i see in the debugger is that the string pStr of the function, get fill successfully but it doesn't change the variable "pStrTrama" in main.
żWhat am i doing wrong?
Code:
/*Libraries*/
#include <stdio.h>
#include <process.h>
#include <string.h>
#include <malloc.h>
void getStrFile(char*, FILE*, char*);
int main()
{
char *pStrTrama = NULL;
FILE *source = NULL;
getStrFile(pStrTrama, source, "IDELCLTSDO_180_IATX.txt");
printf("%s", pStrTrama);
system("PAUSE");
return(0);
}
void getStrFile(char *pStr, FILE *pFile, char *pFileName)
{
int byte = 0;
char ch;
fopen_s(&pFile, pFileName, "r");
if (pFile == NULL)
{
printf("Can't open source file...\n");
exit(1);
}
while ((ch = fgetc(pFile)) != EOF)
byte++;
pStr = (char*)calloc(byte, sizeof(char));
rewind(pFile);
for (int x = 0;(ch = fgetc(pFile)) != EOF; x++)
{
pStr[x] = (int)ch;
pStr[x + 1] = '\0';
}
fclose(pFile);
}
Thanks!