Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 4th, 2005, 4:38 AM   #1
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
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
Berto is offline   Reply With Quote
Old Apr 4th, 2005, 4:45 AM   #2
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
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.
Berto is offline   Reply With Quote
Old Apr 4th, 2005, 7:02 AM   #3
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
Originally Posted by Berto
I am not that stupid to be trying to assign an int to and char or vice versa
How would that be stupid? This is perfectly legal C/C++:
int i = 5;
// assign a char to an int
char c = i;
// assign an int to a char
i = c;
heh
Cerulean is offline   Reply With Quote
Old Apr 4th, 2005, 7:24 AM   #4
Daniel_kd
Newbie
 
Daniel_kd's Avatar
 
Join Date: Apr 2005
Posts: 22
Rep Power: 0 Daniel_kd is on a distinguished road
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.
Daniel_kd is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:22 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC