![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| reverse an integer | ali560045 | Shell Programming and Scripting | 4 | 05-20-2008 03:15 AM |
| Cannot store integer value | bennichan | Shell Programming and Scripting | 5 | 04-10-2008 02:20 PM |
| how to pass integer | ramneek | IP Networking | 1 | 08-25-2005 08:40 AM |
| How to get a rodom integer | toddor | High Level Programming | 2 | 10-10-2001 07:21 AM |
| Integer to String | psilva | High Level Programming | 2 | 08-17-2001 12:14 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
ok, i tried something i did before and i seem to be getting somewhere here. just one problem.
line 100.25: 1506-068 (W) Operation between types "int*" and "int" is not allowed. Code:
+93 printf("\nEnter 4 Digit Reference Number:\n");
+94 scanf("%d",&temp3[count]);
+95 while(temp3[count]<1000||temp3[count]>9999){
+96 printf("\nInvalid Option!");
+97 printf("\nEnter 4 Digit Reference Number:\n");
+98 scanf("%d",&temp3[count]);
+99 }
+100 refNumber[count]=temp3[count];
thanks! primal _____________________________ im stuck! this is probably something basic that i just forgot how to do but ive been trying to get this working for a few days now and i cant figure it out. heres the deal: part of the program im writing prompts the user for a 4 digit number and stores it into int *refNumber[4]. ive passed it to my function call, int insert(char *name[],int *refNumber[], int) but getting the info to store is whats not working. ive tried a few ways, but nothing. this is how i did it for the name.... (inside a while loop) printf("Enter clients name:\n"); fflush(stdin); scanf("%[^\n]",temp); name[count]=(char *)malloc(strlen(temp)+1); strcpy(name[count],temp); temp is a a var (char temp[30]) **reference number code here ** count++; ive tried strlen, strcpy, sizeof, a few others that i cant recall right now. im completely lost. would any one be able to help me? thanks! primal p.s. if more code is required let me know Last edited by primal; 03-09-2002 at 03:31 PM.. |
|
||||
|
oh im saving 1 number per array? thats not good.
"But the length of a 4 digit integer is predictable. And you can store all 4 digits in one int. So you should have an array of ints. You should pass that array to your function. And your function should just store the int in the array" how do i do that? thanks! primal heres my code, well the bit that pertains to this Code:
void main(){
char choice[6], *name[30], ch;
int num, count=0, *refNumber[4];
int insert(char *name[],int *refNumber[],int);
count=insert(name,refNumber,count);
}
int insert(char *name[],int *refNumber[],int count){
int i, temp3[4];
char temp[30],choice[5];
printf("\nDo you want to enter client data?\n");
fflush(stdin);
scanf("%[^\n]", choice);
for(i=0;choice[i]!='\0';i++){
choice [i] = toupper(choice[i]);
}
while((!(strcmp(choice,"YES")==0) && !(strcmp(choice,"NO") == 0))){
printf("\nInvalid option!\t \"yes\" or \"no\"\n");
fflush (stdin);
scanf("%[^\n]", choice);
for(i=0;choice[i]!='\0';i++){
choice [i] = toupper(choice[i]);
}
}
while(strcmp(choice, "YES") ==0){
fflush(stdin);
printf("\nEnter Client Name:\n");
fflush(stdin);
scanf("%[^\n]", temp);
name[count] = (char *) malloc (strlen(temp) + 1);
strcpy (name[count], temp);
printf("\nEnter 4 Digit Reference Number:\n");
scanf("%d",&temp3[count]);
while(temp3[count]<1000||temp3[count]>9999){
printf("\nInvalid Option!");
printf("\nEnter 4 Digit Reference Number:\n");
scanf("%d",&temp3[count]);
}
refNumber[count]=temp3[count];
count++;
printf("\nDo you want to enter data for another client?\n");
fflush(stdin);
scanf("%[^\n]", choice);
for(i=0;choice[i]!='\0';i++){
choice [i] = toupper(choice[i]);
}
while((!(strcmp(choice,"YES")==0) && !(strcmp(choice,"NO") == 0))){
printf("\nInvalid option!\t \"yes\" or \"no\"\n");
fflush (stdin);
scanf("%[^\n]", choice);
for(i=0;choice[i]!='\0';i++){
choice [i] = toupper(choice[i]);
}
}
}
return count;
}
|
|
|||||
|
You are not checking for overflowing your arrays. I put that in. It's the LISTMAX stuff and a slight mode to your scanf's. I didn't like the way you passed count into your function. So I did that a little differently. And I added a few statements to print out the arrays to be sure that it was working.
You will want to bump up LISTMAX, I made it low for easy testing... Here is my modified code... Code:
#include <stdio.h>
#define LISTMAX 3
void main(){
char *name[LISTMAX], ch;
int num, count, refNumber[LISTMAX];
int i;
int insert(char *name[],int refNumber[]);
count=insert(name,refNumber);
printf("count = %d \n", count);
for(i=0; i<count; i++) {
printf("%30s %d\n", name[i], refNumber[i]);
}
exit(0);
}
int insert(char *name[],int refNumber[]){
int count;
int i, temp3[4];
char temp[30],choice[5];
count=0;
printf("\nDo you want to enter client data?\n");
fflush(stdin);
scanf("%5[^\n]", choice);
for(i=0;choice[i]!='\0';i++){
choice [i] = toupper(choice[i]);
}
while((!(strcmp(choice,"YES")==0) && !(strcmp(choice,"NO") == 0))){
printf("\nInvalid option!\t \"yes\" or \"no\"\n");
fflush(stdin);
scanf("%5[^\n]", choice);
for(i=0;choice[i]!='\0';i++){
choice [i] = toupper(choice[i]);
}
}
while(strcmp(choice, "YES") ==0){
printf("\nEnter Client Name:\n");
fflush(stdin);
scanf("%30[^\n]", temp);
name[count] = (char *) malloc (strlen(temp) + 1);
strcpy (name[count], temp);
printf("\nEnter 4 Digit Reference Number:\n");
fflush(stdin);
scanf("%4d",&temp3[count]);
while(temp3[count]<1000||temp3[count]>9999){
printf("\nInvalid Option!");
printf("\nEnter 4 Digit Reference Number:\n");
fflush(stdin);
scanf("%d",&temp3[count]);
}
refNumber[count]=temp3[count];
count++;
if (count == LISTMAX) {
printf("tables are full\n");
return LISTMAX;
}
printf("\nDo you want to enter data for another client?\n");
fflush(stdin);
scanf("%[^\n]", choice);
for(i=0;choice[i]!='\0';i++){
choice [i] = toupper(choice[i]);
}
while((!(strcmp(choice,"YES")==0) && !(strcmp(choice,"NO") == 0))){
printf("\nInvalid option!\t \"yes\" or \"no\"\n");
fflush(stdin);
scanf("%[^\n]", choice);
for(i=0;choice[i]!='\0';i++){
choice [i] = toupper(choice[i]);
}
}
}
return count;
}
|
|
||||
|
thank you so much!
im going to look over your code right now. primal |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|