Take the 2-minute tour ×

I have googled this and see many answers, but none fits my situation. This is my main():

char * cString;
puts("Please enter data you want to encrypt.");
cString = getInput(cString, &iStringSize);
printf("The message is: %s\n\n", cString);

char * strEncrypt;
strEncrypt = encrypt(cString, offset);
printf("The encrypted message is: %s\n\n", strEncrypt);

return 0;

This program basically reads in an arbitrary input, then encrypt it. This is the getInput function:

char * getInput(char *cString, int * iStringSize)
    puts("Begin reading input.");
    char buffer[CHUNK];
    int iBufferSize;
    while(fgets(buffer, CHUNK - 1, stdin) != NULL)
        iBufferSize = strlen(buffer);
        *iStringSize += iBufferSize;
        cString = realloc(cString, sizeof(char) * (*iStringSize + 1));
        strcat(cString, buffer);
    printf("String size is: %d\n", *iStringSize);
    puts("Reading successful");
    return cString;

As shown above, cString is char pointer. The getInput function also returns char pointer. However, I keep getting the message: assignment makes pointer from integer without cast [enabled by default]

This happens when I compile the code.

The same happens to this function

char * encrypt(char *str, int offset)
    puts("Begin encryption.");
    char * strEncrypt = malloc(sizeof(char) * (strlen(str) + 1));
    int i;
        //substitution algorithm using int offset variable.
        //I accessed str and strEncrypt using pointer arithmetic

    puts("Encryption success!");
    return strEncrypt;

Please no suggestion on error handling of realloc.

share|improve this question
Is your getInput function declared before it is used? If not, the compiler will think it returns an int. –  Vaughn Cato Apr 9 at 4:21
at what line you are getting warning? –  SGG Apr 9 at 4:34
Please mention the line number where you are getting error. And note that in getInput() function you are incrementing iStringSize value, before that it should be initialised to zero. –  Vinay Apr 9 at 4:45
I get the warnings in these lines: cString = getInput(cString, &iStringSize); strEncrypt = encrypt(cString, offset); so when I assign the result of functions to the pointer. –  knt5784 Apr 9 at 4:46
Googling the exact error message in the title, nearly half of the many answers fit your exact situation, so I'm lost why you think otherwise. And this isn't the only problem in your code. You're passing an indeterminate pointer cString to getInput invoking undefined behavior. Sending it to realloc just solidifies that improper action. Initialize it to NULL or a valid allocation result prior to calling getInput. –  WhozCraig Apr 9 at 6:52

1 Answer 1

up vote 1 down vote accepted

Declare getInpyt and encrypt function before their first use otherwise compiler assumes these functions return int and accept variable number of parameters.

You can declare them by using any one of 3 ways given below.

  1. Include appropriate header files containing their declarations.
  2. Include declarations manually in global scope or local scope before you first access them.
  3. Move the definition of these functions before you first access them.
share|improve this answer

Your Answer


