Hi,
I am testing a code from c tutorial and tried below code and did compile and it fails to incompatible type in return.. and I am not sure why ?
Code:
#include <stdio.h>
struct invStruct {
char manuf[25];
char model[15];
int diskSpace;
int memSpace;
int quantity;
float cost;
float price;
}
main()
{
int ctr;
struct invStruct items[3]; /* Array of 3 structure variables */
for ( ctr = 0; ctr < 3; ctr++ )
{
printf( "What is the manufacturer of item #%d?\n", (ctr + 1) );
gets( items[ctr].manuf );
puts( "what is the mode? ");
gets(items[ctr].model);
puts("how many megabytes of disk space? ");
scanf(" %d", &items[ctr].diskSpace);
puts("How many megabytes of memory space? ");
scanf(" %d", &items[ctr].memSpace);
puts("How many are there? ");
scanf(" %d", &items[ctr].quantity);
puts("How much does the item cost? ");
scanf(" %d", &items[ctr].quantity);
puts("How much does the item cost? ");
scanf(" %f", &items[ctr].cost);
puts("How much does the item retail for? ");
scanf(" %f", &items[ctr].price);
getchar(); /* clears input of last newline pressed for next round of input */
} /* Now prints the data */
printf("\n\nHere is the inventory: \n");
for ( ctr = 0; ctr < 3; ctr++ )
{
printf("#%d: Manufacturer: %s", (ctr + 1), items[ctr].manuf);
printf("\nModel: %s", items[ctr].model);
printf("\nDisk: %d megabytes\t", items[ctr].diskSpace);
printf("Memory: %d megabytes\t", items[ctr].memSpace);
printf("Quantity: %d units\n", items[ctr].quantity);
printf("Cost: $%.2f\t", items[ctr].cost);
printf("Selling price: $%.2f\n\n", items[ctr].price);
}
return 0;
}
result of gcc'ing
Code:
root@my-laptop:/code_upload/c# gcc -o struct.o struct.c
struct.c: In function âmainâ:
struct.c:51: error: incompatible types in return
struct.c:16: warning: return type of âmainâ is not âintâ
root@my-laptop:/code_upload/c#