Reputation: 99
15:9: error: incompatible types when assigning to type ‘char[3]’ from type ‘char *’
#include <stdio.h>
int main(int argc, char *argv[])
{
char servIP[3];
int servPortNum;
if(argc<3)
{
printf("Usage: clientApp servIP servPortNum\n");
}
servIP = argv[1];
servPortNum = atoi(*argv[2]);
}
Upvotes: 0
Views: 1185
Reputation: 5456
You can't assign an array like this. Assign it member-by-member, or use char *servIP
instead.
Upvotes: 0
Reputation: 145919
You cannot assign to arrays. Use strcpy
or strncpy
function to copy a string in an array of char
.
Upvotes: 1
Reputation: 14083
servIP
is an array, not a pointer. Arrays convert to pointers, but they aren't the same thing and pointers don't convert to arrays.
Upvotes: 0
Reputation: 16728
strncpy (servIP, argv [1], sizeof (servIP) - 1);
servIP [sizeof (servIP) - 1] = 0;
But are you sure servIP
is big enough for an IP address?
Upvotes: 2