Issue
I want to convert the argv[1] to an int. But I get this warning:
xorcipher.c:7:9: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]
And the printf display me
-799362156
if I type
./xorcipher 4
How to correct this?
Here is my code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char* argv[])
{
int key_length = atoi(argv[1]);
printf("key_length = %d", &key_length);
return(0);
}
Solution
You are passing the address of key_length
, where as the error states, printf
expects just the value. Try this:
printf("key_length = %d", key_length);
See this tutorial on C format specifiers.
Answered By - Nik Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.