•
•
•
•
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
![]() |
•
•
Join Date: Sep 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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");
} C Syntax (Toggle Plain Text)
scanf("%s",&make); scanf("%s",&model); scanf("%s", &color); scanf("%s",&plate); scanf("%s ",&sfname);
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.
c Syntax (Toggle Plain Text)
scanf("%s ",&sfname);
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.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation:
Rep Power: 40
Solved Threads: 972
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.
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
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);if( make[strlen(make)-1] == '\n')
make[strlen(make)-1] = 0; Last edited by Ancient Dragon : Sep 13th, 2007 at 10:29 pm.
•
•
•
•
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);
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.
•
•
Join Date: Sep 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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");
}
>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.
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.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation:
Rep Power: 40
Solved Threads: 972
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- warning: assignment makes pointer from integer without a cast (C)
- strcmp without cast (C)
- makes pointer from integer without a cast (C)
- total newb - "passing arg 2 of `strcpy' makes pointer from integer without a cast" (C++)
Other Threads in the C Forum
- Previous Thread: Config File
- Next Thread: graphic problem in c



Linear Mode