whats wrong here??

Cannot fix this error. Help!! Line 7 shows the error as a comment.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <readline/readline.h>
#include <stdio.h>
int main(int argc, const char * argv[])
{
    int j;
    printf("Where should I start counting? ");
    int i = readline(NULL);//Incompatible pointer to integer conversion initializing 'int' with an expression of type 'char *'
    
    for (j=i; j>=0; j--)
    {
        if (j % 3 == 0)
        {
            printf("%d\n", j);
            if (j % 5 == 0)
                printf("Found one!\n");
        }
    }
    
    return 0;
}
Last edited on
Since you haven't included readline.h, we don't know what its declaration is.
From the error message, it would appear that readline() returns a char pointer, which you're trying to assign to an int.
Last edited on
Use a string stream
i still don't get it. all i am trying to do here is prompt the user to input a number and then store the user input in variable i without using the scanf. now is it possible to fix this code.
If you want to write C++ code then don't use <stdio.h> (say printf(), scanf(), ...). Instead of you should use streams as Code Apperentice said. See http://www.cplusplus.com/reference/iolibrary/ for details and a lot of examples.
As previously requested, please show us readline.h
Last edited on
Topic archived. No new replies allowed.