| | |
structures and functions woohoo!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 16
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <stdio.h> int i,type; int buffer[100],line[50]; struct student { char name[20]; int age; int id; }; struct student students[3]; int main() { for(i=0;i<3;i++) { printf("please enter your name:\n"); fgets(students[i].name,sizeof(students[i].name),stdin); printf("please enter your age:\n"); fgets(buffer,sizeof(buffer),stdin); sscanf(buffer,"%d",&students[i].age); printf("please enter your id:\n"); fgets(buffer,sizeof(buffer),stdin); sscanf(buffer,"%d",&students[i].id); } while(1) { int *ptr=students; printf("Please enter the # for the program you want to run:\n"); fgets(line,sizeof(line),stdin); sscanf(line,"%d",&type); if(type==5) break; switch(type) { int insertsort(int list[],*ptr) /*function to sort an array of integers */ { int j, k, index; or (j=1;j<students[i-1];j++) { index=list[j]; k=j; while ((k>0) && (list[k-1]>index)) { list[k] = list[k-1]; k=k-1; } list[k] = index; } } case 1:/* sort by name */ case 2:/* sort by age */ insertsort(students_ptr->age); case 3:/* sort by id */ insertsort(*ptr[i].id); case 4: printf("1-sort by name\n2-sort by age\n3-sort by id\n4-help\n5-Quit\n"); continue; default: printf("enter 4 for help\n"); continue; } prinf("idk\n"); } return(0); }
Last edited by alc6379; Nov 4th, 2004 at 11:39 pm. Reason: added [code] tags
>passing arg 1 of `fgets' from incompatible pointer type
fgets expects a pointer to char. You pass it a pointer to int because buffer is defined as an array of int. Change buffer to be an array of char and the warning will go away.
>should this be in my while loop, or outside of it?
Functions can only be defined at the top lexical level of a program. This means that your function must be outside of main, which is most certainly outside of the loop.
fgets expects a pointer to char. You pass it a pointer to int because buffer is defined as an array of int. Change buffer to be an array of char and the warning will go away.
>should this be in my while loop, or outside of it?
Functions can only be defined at the top lexical level of a program. This means that your function must be outside of main, which is most certainly outside of the loop.
New members chased away this month: 3
![]() |
Similar Threads
- Structures and functions (C++)
- Anyone have a good programes..? PlZ (C)
- Please help.... (C)
- need help with a project (Shell Scripting)
- Help for Air Lines Reservition System (C)
- drink machine (C++)
Other Threads in the C++ Forum
- Previous Thread: Looking for _gcvt(double,int,string)
- Next Thread: When does the memory get allocated to the function
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






