Results 1 to 25 of 26
Thread: C !!!
Hybrid View
-
18th December 2006 23:20 #1
C !!!
:
C , , :
Code:void load(char *file); //
Code:int main(int argc, char *argv[2]) { .... .... load(argv[1]) // ; .... ...., . if ((fp=fopen(file,"rb"))==NULL) -> if ((fp=fopen(file[1],"rb"))==NULL) " [Warning] passing arg 1 of `fopen' makes pointer from integer without a cast " .Code:void load(char *file) { FILE *fp; int i; if ((fp=fopen(file,"rb"))==NULL) { printf("Catalago file not found !\n"); return; } if(fread(&last, sizeof last,1,fp)!=1) { printf("Error reading count !\n"); exit(1); } for (i=0;i<=last;i++) if(fread(&car[i],sizeof(struct catalog),1,fp)!=1) { printf("Error reading count !\n"); exit(1); } fclose(fp); }
, !
-
18th December 2006 23:44 #2
:
int main(int argc, char *argv[2])
:
int main(int argc, char *argv[])
? ? ? , . , .Last edited by Exhumator; 18th December 2006 at 23:59.
-
19th December 2006 00:48 #3
file char*, .. , '\0'. file[1], , char. char , char*, char int, char* ( , , ). , . C++ , .
, -, . ?Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
19th December 2006 21:23 #4
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 50
//
int menu(void);
void display(int i);
void search_by_colour(void);
void search_by_id(void);
void save(char *file);
void load(char *file);
void enter (void);
// ,
struct catalog {
char name[30];
char colour[10];
int id;
int price;
int volume;
} car[MAX];
char file[30];
int last; //
int main(int argc, char *argv[])
{
int i,d,m,y,choice;
// ( )
if (argc!=2)
{
printf("\n");
printf("**** Cars Catalog System v1.0 by Mitko Kostov **** \n");
printf("\n");
printf("\n");
printf("Usage : catalog <file> \n");
exit(1);
}
printf("Enter date ( dd/mm/yy ): ");
scanf("%d/%d/%d",&d,&m,&y);
//
do {
choice=menu();
switch(choice) {
case 1: enter();
break;
case 2: load(argv[1]);
break;
case 3: search_by_colour();
break;
case 4: ;
break;
case 5: search_by_id();
break;
case 6: save(argv[1]);
break;
}
} while (choice!=7);
return 0;
}
int menu (void) {
int i;
char str[80];
printf("Cars catalog: \n");
printf("1. Enter data\n");
printf("2. Load data\n");
printf("3. Search by colour\n");
printf("4. Search by colour, order by price\n");
printf("5. Search by ID\n");
printf("6. Save data\n");
printf("7. Quit\n");
do {
printf("Choose your selection: ");
gets(str);
i=atoi(str);
printf("\n");
} while(i<1 || i>6);
return i;
}
void search_by_colour (void) {
char colour[80];
int found,i;
printf("Enter colour: \n");
gets(colour);
found=0;
for(i=0;i<last;i++) {
if(!strcmp(colour,car[i].colour)) {
display(i);
found=1;
printf("\n");
}
if (!found) printf("Car with %c was not found !\n",colour);
}
}
void search_by_id(void) {
int id,i,found;
printf("Enter ID: ");
scanf("%d",&id);
found=0;
for(i=0;i<last;i++) {
if(id!=car[i].id) {
display(i);
found=1;
printf("\n");
}
if(!found) printf("Car with ID %d was not found !\n",id);
}
}
void save(char *file) {
FILE *fp;
int i;
if ((fp=fopen(file,"wb"))==NULL)
{
printf("Cannot open catalog file !\n");
exit(1);
}
if(fwrite(&last,sizeof last,1,fp)!=1)
{
printf("Error writing count !\n");
exit(1);
}
if (fwrite(&car[i],sizeof(struct catalog),1,fp)!=1)
{
printf("Error writing data !\n");
exit(1);
}
fclose(fp);
}
void load(char *file)
{
FILE *fp;
int i;
if ((fp=fopen(file,"rb"))==NULL)
{
printf("Catalago file not found !\n");
return;
}
if(fread(&last, sizeof last,1,fp)!=1)
{
printf("Error reading count !\n");
exit(1);
}
for (i=0;i<=last;i++)
if(fread(&car[i],sizeof(struct catalog),1,fp)!=1)
{
printf("Error reading count !\n");
exit(1);
}
fclose(fp);
}
void display( int i) {
printf("ID:%s\n",car[i].id);
printf("Name :%s",car[i].name);
printf("Colour :%s",car[i].colour);
printf("Price :%s",car[i].price);
printf("Volume :%s",car[i].volume);
}
void enter(void) {
int i;
for (i=last;i<MAX;i++)
{
printf("Enter name of the car:\n ");
gets(car[i].name);
printf("Enter colour of the car: ");
gets(car[i].colour);
printf("Enter price of the car: ");
scanf("%s",&car[i].price);
printf("Enter volume of the engine: ");
scanf("%s",&car[i].volume);
printf("Enter id of the car: ");
scanf("%s",&car[i].id);
}
last=i;
}
( save() ) , Bloodshed DevC++ 4.9.9.2
-
20th December 2006 21:20 #5
, for save(), i :
, , .Code:if (fwrite(&car[i],sizeof(struct catalog),1,fp)!=1)
Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
20th December 2006 22:12 #6
1. enter() gets(), - scanf() ? .
2. gets() menu() "" do .. while "Choose your selection" .
3. - int found; :4. -...Code:... display(i); printf("\n"); return; } printf("Car with %c was not found !\n",int); }
Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19
-
21st December 2006 00:17 #7
-
21st December 2006 07:46 #8
,
typedef struct _catalog {
char szName[30];
char szColour[10];
int iId;
int iPrice;
int iVolume;
} Car, *pCar; // -
pCar Cars;
Cars = (pCar)malloc(MAX*sizeof(Car));
. Cars e , . :
Cars[1].id = 5 .
:
free(Cars);
:
http://en.wikipedia.org/wiki/Malloc
, run-time, .EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
21st December 2006 15:33 #9: realloc().Code:
#include <vector> std::vector<Car*> cars;
Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
21st December 2006 15:38 #10
-
22nd December 2006 14:11 #11
main() , .
Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
24th December 2006 16:02 #12
-
26th December 2006 13:03 #13
Bombera -. malloc. realloc:
: :Code:Car* newCars = (Car *)realloc(Cars, newSize * sizeof(Car)); if (NULL != newCars) Cars = newCars; else ... ...
Code:void save(Car* cars, int numCars) { ... ... }Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
10th January 2007 11:20 #14
-
11th January 2007 13:50 #15
. ( ). ( , ). ->, :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//
int menu(void);
void display(int i);
void search_by_colour(void);
void search_by_id(void);
void save(char *file);
void load(char *file);
void enter (void);
// ,
typedef struct catalog {
char name[30];
char colour[10];
int id;
int price;
int volume;
} car, *pcar;
char file[30];
int last=0; //
int main(int argc, char *argv[])
{
pcar cars;
int i,d,m,y,choice,MAX;
// ( )
if (argc!=2)
{
printf("\n");
printf("**** Cars Catalog System v1.0 by Mitko Kostov **** \n");
printf("\n");
printf("\n");
printf("Usage : catalog <file> \n");
exit(1);
}
printf("Enter date ( dd/mm/yy ): ");
scanf("%d/%d/%d",&d,&m,&y);
if ( d<1 || d>31 || m<1 || m>12 || y<1900 || y>2007 )
{
printf(Wrong entered date !);
exit(1);
}
printf(Enter number of cars you want to enter in the database file: );
scanf(%d,&MAX);
cars=(pcar)malloc(MAX*sizeof(car));
//
do {
choice=menu();
switch(choice) {
case 1: enter();
break;
case 2: load(argv[1]);
break;
case 3: search_by_colour();
break;
case 4: ;
break;
case 5: search_by_id();
break;
case 6: save(argv[1]);
break;
}
} while (choice!=7);
return 0;
}
int menu (void) {
int i;
char str[80];
printf("Cars catalog: \n");
printf("1. Enter data\n");
printf("2. Load data\n");
printf("3. Search by colour\n");
printf("4. Search by colour, order by price\n");
printf("5. Search by ID\n");
printf("6. Save data\n");
printf("7. Quit\n");
do {
printf("Choose your selection: ");
gets(str);
i=atoi(str);
printf("\n");
} while(i<1 || i>6);
return i;
}
void search_by_colour (void) {
char colour[80];
int found,i;
printf("Enter colour: \n");
gets(colour);
found=0;
for(i=0;i<last;i++) {
if(!strcmp(colour,cars[i].colour)) {
display(i);
found=1;
printf("\n");
}
if (!found) printf("Car with %c was not found !\n",colour);
}
}
void search_by_id(void) {
int id,i,found;
printf("Enter ID: ");
scanf("%d",&id);
found=0;
for(i=0;i<last;i++) {
if(id!=cars[i].id) {
display(i);
found=1;
printf("\n");
}
if(!found) printf("Car with ID %d was not found !\n",id);
}
}
void save(char *file) {
FILE *fp;
int i;
for(i=0;i<MAX;i++) {
if ((fp=fopen(file," a+"))==NULL)
{
printf("Cannot open catalog file !\n");
exit(1);
}
if(fwrite(&last,sizeof MAX,1,fp)!=1)
{
printf("Error writing count !\n");
fclose(fp);
exit(1);
}
if (fwrite(&cars[i],sizeof(struct catalog),1,fp)!=1)
{
printf("Error writing data !\n");
fclose(fp);
exit(1);
}
}
fclose(fp);
}
void load(char *file)
{
FILE *fp;
int i;
if ((fp=fopen(file,"rb"))==NULL)
{
printf("Catalag file not found !\n");
return;
}
if(fread(&last, sizeof MAX,1,fp)!=1)
{
printf("Error reading count !\n");
exit(1);
}
for (i=0;i<=last;i++)
if(fread(&car[i],sizeof(car catalog),1,fp)!=1)
{
printf("Error reading count !\n");
exit(1);
}
fclose(fp);
}
void display( int i) {
printf("ID:%s\n",cars[i].id);
printf("Name :%s",cars[i].name);
printf("Colour :%s",cars[i].colour);
printf("Price :%s",cars[i].price);
printf("Volume :%s",cars[i].volume);
}
void enter(void) {
int i;
for (i=last;i<MAX;i++)
{
printf("Enter name of the car: ");
scanf(%s,&cars[i].name);
printf("Enter colour of the car: ");
scanf(%s,&cars[i].colour);
printf("Enter price of the car: ");
scanf("%d",&cars[i].price);
printf("Enter volume of the engine: ");
scanf("%d",&cars[i].volume);
printf("Enter id of the car: ");
scanf("%d",&cars[i].id);
}
last=i;
}
-
16th January 2007 18:00 #16
-
16th January 2007 18:19 #17
. . , . ?
.. . , .Last edited by Bombera; 16th January 2007 at 18:27.
EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
16th January 2007 18:51 #18
, , . , , , :
.Code:typedef struct catalog { char name[30]; char colour[10]; int id; int price; int volume; } car, *pcar;
.
: , .
-
16th January 2007 19:30 #19
, . ?
EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
16th January 2007 21:12 #20
-
16th January 2007 22:47 #21
, , , . , , . , , /++.
, , .EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
16th January 2007 23:19 #22
-
18th January 2007 01:31 #23
, ,
Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
18th January 2007 08:35 #24
http://flyier.hit.bg/main.txt
STABLE, *child , *parent ...
-
18th January 2007 12:46 #25
- - .
, "" (*parent) (*child). . , child . , parent . , child , , , child . , child parent , , child parent .
, ( ""), ( , ).
child , parent - , - , ,
Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in