User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,488 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,734 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 2167 | Replies: 10
Reply
Join Date: Sep 2007
Posts: 4
Reputation: Ballar32 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Ballar32 Ballar32 is offline Offline
Newbie Poster

integer without a cast

  #1  
Sep 13th, 2007
I'm getting a the error "passing arg1 of 'strcpy' makes pointer from integer without a cast....

#include<stdio.h>
#include <stdlib.h>

struct node {
       char make;
       char model;
       int  year;
       char color;
       char plate;
       struct node* next;
};
  
void menu();
void insert(struct node** head, char make, char , int, char, char);

int main(void){
    
    struct node* head = NULL;
    char make, model,plate,sfname,fname,color;
    int x,year;
    menu();
    scanf("%d",&x);
    
    switch(x){
              
                   case 1:
                             printf("Enter make: ");
                             scanf("%s",&make);
                             printf("Enter model: ");
                             scanf("%s",&model);
                             printf("Enter year: ");
                             scanf("%d", &year);
                             printf("Enter color: ");
                             scanf("%s", &color);
                             printf("Enter license plate number");
                             scanf("%s",&plate);
                             insert(&head,make,model,year,color,plate);
                             break;
                   
                   case 2:   printf("Enter the license plate number of the vehicle to remove");
                             scanf("%s ", &plate);
                             //del();
                             break;
                   
                   case 3:   printf("Here are all vehicles:\n");
                             //printcars();
                             break;
                   
                   case 4:   printf("Enter a filename to save as ");
                             scanf("%s ",&sfname);
                             //savetfile();
                             break;
                   
                   case 5:   printf("Enter filename to load ");
                             scanf("%s ",&fname);
                             break;
                   
                   case 0:   printf("Thank you using this program!");
                             break;
    default: "Not an options";
    
    }
    
    system("PAUSE");
    return 0;
}

void insert(struct node** head, char make,char model, int year, char color, char plate){
     
     struct node* newnode;
     struct node* crnt;
     
     newnode = (struct person*)malloc(sizeof(struct node));
     strcpy(make,newnode->make);
     strcpy(model,newnode->model);
     //newnode->year = year;
     strcpy(color, newnode->color);
     strcpy(plate, newnode->plate);

 
     
     newnode->next = crnt->next;
     crnt->next = newnode;
     
     
}


void menu(){
     
     printf("Here are your options:\n1) Insert a vehicle\n2) Delete a vehicle\n3) Print all vehicles\n4) Save to file\n5) Load from file\n0) Quit\n");
     
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,515
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 489
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: integer without a cast

  #2  
Sep 13th, 2007
You forgot to include string.h.
I'm here to prove you wrong.
Reply With Quote  
Join Date: Dec 2006
Posts: 1,569
Reputation: Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold Aia is a splendid one to behold 
Rep Power: 12
Solved Threads: 114
Aia's Avatar
Aia Aia is offline Offline
Posting Virtuoso

Re: integer without a cast

  #3  
Sep 13th, 2007
  1. scanf("%s",&make);
  2. scanf("%s",&model);
  3. scanf("%s", &color);
  4. scanf("%s",&plate);
  5. scanf("%s ",&sfname);
These will have an effect that you did not intended.
The format %s is for strings or arrays of type char, and when you pass it to scanf you don't need the & operator. Futhermore you have declared those variables as a single type char. In these case it would be scanf("%c", &model) as an example. Change the argument in the scanf() and make all those single char variables into arrays of type char, is what the rest of you code seems to indicate.
  1. scanf("%s ",&sfname);
Eliminate the extra space between the s and the closing "
Last edited by Aia : Sep 13th, 2007 at 8:02 pm.
At the very moment that I find myself in the side of the mayority, I will know that I need to re-think my ideas. ~ In my book.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 972
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: integer without a cast

  #4  
Sep 13th, 2007
Also we normally discourage the use of scanf() with"%s" because it will allow you to corrupt the program's memory by scribbling outside the boundry of the arrays. For example if make is declared as an array of 10 characters and you type 15 characters then scanf() will write the extra 5 characters somewhere in memory -- where is anyone's guess. A second disadvantage of scanf() with "%s" is that it will not capture more than one word -- it stops copying from the keyboard at the first white-space character. So you can not enter a make that has two or more spaces in the name.

The solution is to either get the characters one character at a time from the keyboard buffer (hard way) or call fgets() which will limit the input to the size of the program's input buffer.
char make[10];
printf("Enter make\n");
fgets(make, sizeof(make), stdin);
Now, one disadvantage of fgets() is that it will insert the '\n' character at the end of the input buffer if there is enough room. So you have to strip it back out
if( make[strlen(make)-1] == '\n')
    make[strlen(make)-1] = 0;
Last edited by Ancient Dragon : Sep 13th, 2007 at 10:29 pm.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Dec 2006
Posts: 232
Reputation: ssharish2005 is on a distinguished road 
Rep Power: 2
Solved Threads: 18
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: integer without a cast

  #5  
Sep 14th, 2007

I'm getting a the error "passing arg1 of 'strcpy' makes pointer from integer without a cast....

This is where you get the error right
strcpy(make,newnode->make);
strcpy(model,newnode->model);
strcpy will get two char pointer (char *) as an argument. But you are passing just a (char). Which in fact is wrong. The char is internal converted to ASCII that is an int. Hence you get that an error.

In your case, since you are just copy a single char. You could just use a assignment operator to assign value. So for example you could replace the above statment by this

newnode->make = make;
newnode->model = model

strcpy are basically used to copy from one stirng to another, but not from one char to another. And offcouse others advice should be considered as well. In fact they are very important on improving your code.


ssharish
Last edited by ssharish2005 : Sep 14th, 2007 at 7:50 am.
Reply With Quote  
Join Date: Sep 2007
Posts: 4
Reputation: Ballar32 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Ballar32 Ballar32 is offline Offline
Newbie Poster

Re: integer without a cast

  #6  
Sep 14th, 2007
I've included <string.h>, changed from single characters to arrays, and i'n still getting the same error.

#include <stdio.h>
#include <stdlib.h>
#include <string.h> 

struct node {
       char make[16];
       char model[16];
       int  year;
       char color[16];
       char plate[16];
       struct node* next;
};
  
void menu();
void insert(struct node** head, char make, char , int, char, char);

int main(void){
    
    struct node* head = NULL;
    char make, model,plate,sfname,fname,color;
    int x,year;
    menu();
    scanf("%d",&x);
    
    switch(x){
              
                   case 1:
                             printf("Enter make: ");
                             scanf("%s", &make);
                             printf("Enter model: ");
                             scanf("%s", &model);
                             printf("Enter year: ");
                             scanf("%d", &year);
                             printf("Enter color: ");
                             scanf("%s", &color);
                             printf("Enter license plate number: ");
                             scanf("%s", &plate);
                             insert(&head,make,model,year,color,plate);
                             break;
                   
                   case 2:   printf("Enter the license plate number of the vehicle to remove");
                             scanf("%s ", &plate);
                             //del();
                             break;
                   
                   case 3:   printf("Here are all vehicles:\n");
                             //printcars();
                             break;
                   
                   case 4:   printf("Enter a filename to save as ");
                             scanf("%s ",&sfname);
                             //savetfile();
                             break;
                   
                   case 5:   printf("Enter filename to load ");
                             scanf("%s ",&fname);
                             break;
                   
                   case 0:   printf("Thank you using this program!");
                             break;
    default: "Not an options";
    
    }
    printf("It does get to this point");
    system("PAUSE");
    return 0;
}

void insert(struct node** head, char make,char model, int year, char color, char plate){
     
     struct node* newnode;
     struct node* crnt;
     crnt=*head;
     
     newnode = (struct person*)malloc(sizeof(struct node));
     strcpy(make,newnode->make);
     strcpy(model,newnode->model);
     newnode->year = year;
     strcpy(color, newnode->color);
     strcpy(plate, newnode->plate);

     if(crnt->head == NULL)
                   crnt->next=newnode;
                   crnt= crnt->next;
    
 
     
     newnode->next = crnt->next;
     crnt->next = newnode;
     
     
}


void menu(){
     
     printf("Here are your options:\n1) Insert a vehicle\n2) Delete a vehicle\n3) Print all vehicles\n4) Save to file\n5) Load from file\n0) Quit\n");
     
}
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: integer without a cast

  #7  
Sep 14th, 2007
> changed from single characters to arrays, and i'n still getting the same error.
But you didn't change the char parameters to char arrays at the same time.
Reply With Quote  
Join Date: Sep 2007
Posts: 4
Reputation: Ballar32 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Ballar32 Ballar32 is offline Offline
Newbie Poster

Re: integer without a cast

  #8  
Sep 14th, 2007
What do you mean?
Reply With Quote  
Join Date: Sep 2004
Posts: 6,515
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 489
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: integer without a cast

  #9  
Sep 14th, 2007
>I've included <string.h>
So you have.

>changed from single characters to arrays
I can't really help you at this point. Your misunderstanding of data types is so complete and fundamental that it's impossible to write programs until you get a book on C and actually read it.
I'm here to prove you wrong.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 972
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: integer without a cast

  #10  
Sep 14th, 2007
Originally Posted by Ballar32 View Post
What do you mean?


he means like this (note I added the asterisks to make, model and plate because all three require character arrays):
void insert(struct node** head, char *make,char *model, int year, char color, char *plate){
     
Last edited by Ancient Dragon : Sep 14th, 2007 at 1:17 pm.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 3:07 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC