![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() |
Linked List problem
Well no its not but anyhews i have my inked list working just i have a problem with this error message i keep getting....
incompatible types in assignment. I am not that stupid to be trying to assign an int to and char or vice versa :-p.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define BUFFER 1024
struct llnode {
//adrList collection;
char abc[15];
struct llnode *next;
};
typedef struct llnode listNode;
int getIp(char* addrPtr,int type,char* retIP);
void checkIP(listNode **list, char ipAddr[]);
void readList(listNode **list);
int main(){
int value = 0,
count = 0;
char cIn = ' ',
dest[] = "Destination",
src[] = "Source";
listNode *head = NULL;
FILE *file;
if ((file = fopen("test.txt", "r")) == NULL){
printf("Unable to open file");
return 0;
}
while (cIn != EOF){
count = 0;
char ch[BUFFER];
while ((cIn = fgetc(file))!= '\n'){
ch[count++] = cIn;
}
printf("\n\n");
cIn = getc(file);
char *dstPtr = strstr(ch,dest);
char *srcPtr = strstr(ch,src);
char ipAddr[15];
char srcAddr[15];
if (((getIp(dstPtr,1,ipAddr)) == 0 )|| ((getIp(srcPtr,2,srcAddr)) == 0)){
printf("error");
}
printf("ip address : %s\n",ipAddr);
printf("src addr : %s\n\n",srcAddr);
checkIP(&head,srcAddr);
}
fclose(file);
readList(&head);
printf("hold ");
for (;;) ;
}
int getIp(char* addrPtr,int type,char* retIP){
char chP = ' ';
int j,
i = 0;
if (type == 1){//destination
j = 12;
}else if(type == 2){//source
j = 7;
}else{
return 0;
}
while (((chP = addrPtr[j]) != ',') && ((chP = addrPtr[j]) != ' '))
retIP[i++] = addrPtr[j++];
for (i;i<15;i++) //emptys the array to make sure no extra numbers are there
retIP[i] = ' ';
return 1;
}
void checkIP(listNode **list, char ipAddr[]){
listNode *newNode;
char cde = *ipAddr;
newNode = (listNode *)malloc(sizeof(listNode));
newNode->abc = cde;
newNode->next = (* list);
(*list) = newNode;
}
void readList(listNode **list){
listNode *tmp;
tmp = (listNode *)malloc(sizeof(listNode));
tmp = *list;
while (tmp != NULL){
printf("SRC ADDR : %c\n",tmp->abc);
tmp = tmp->next;
}
}my problem is with checkIP function. i cant seem to get it to pass an array of chaacters (string) to the function then from that add into my linked list struct. All i keep getting are errors :/ Any help would be handy ![]() |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
MOD delete this thread as i solved the problem about 2 seconds after asking the question
.Looked up the string.h man page and used strcpy to copy the string instead of string1 = string2. which makes sense. |
|
|
|
|
|
#3 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Quote:
int i = 5; // assign a char to an int char c = i; // assign an int to a char i = c; |
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Apr 2005
Posts: 22
Rep Power: 0
![]() |
the error that the compiler exports when you try to copy char arrays with '=' instead of 'strcpy(char *, char *);' is actually stupid. I had the same exact problem with a list of mine yesterday and it took me some time to find out what the problem was.
Last edited by Daniel_kd; Apr 4th, 2005 at 4:17 PM. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|