Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: C !!!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803

    Exclamation C !!!

    :

    C , , :

    Code:
    void load(char *file); //   
    Code:
    int main(int argc, char *argv[2])
    { 
    ....
    ....
    load(argv[1]) //    ;
    ....
    ....
    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);
                         }
    , . 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 " .

    , !

  2. #2
    Exhumator's Avatar
    Join Date: Jan:2005
    Location: Sofia
    Posts: 14,687
    :
    int main(int argc, char *argv[2])
    :
    int main(int argc, char *argv[])

    ? ? ? , . , .
    Last edited by Exhumator; 18th December 2006 at 23:59.

  3. #3
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    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

  4. #4
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    #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

  5. #5
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    , 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

  6. #6
    Deleted User 4eRNoBiL's Avatar
    Join Date: Oct:2005
    Location:
    Posts: 739

    Post

    1. enter() gets(), - scanf() ? .
    2. gets() menu() "" do .. while "Choose your selection" .
    3. - int found; :
    Code:
    ...
    
    display(i);
    printf("\n");
    return;
    }
    
    printf("Car with %c was not found !\n",int);
    }
    4. -...
    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

  7. #7
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    Quote Originally Posted by 4eRNoBiL View Post
    1. enter() gets(), - scanf() ? .
    2. gets() menu() "" do .. while "Choose your selection" .
    3. - int found; :
    Code:
    ...
    
    display(i);
    printf("\n");
    return;
    }
    
    printf("Car with %c was not found !\n",int);
    }
    4. -...

    1. enter(), , .

    2. , .

    3. , 50 ( #define MAX 50 ) ?

    .

  8. #8
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    ,

    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|

  9. #9
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    Code:
    #include <vector>
    std::vector<Car*> cars;
    : realloc().
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

  10. #10
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    .

    , ., , enter(),save() u load() ? , , .

  11. #11
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    main() , .
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

  12. #12
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    Quote Originally Posted by icaci View Post
    main() , .
    ?

  13. #13
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    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

  14. #14
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    .

    save, ?
    , .

    .

  15. #15
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    . ( ). ( , ). ->, :

    #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;


    }

  16. #16
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    ?

  17. #17
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    . . , . ?
    .. . , .
    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|

  18. #18
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    , , . , , , :
    Code:
    typedef struct catalog {
    char name[30];
    char colour[10];
    int id;
    int price;
    int volume;
    
    } car, *pcar;
    .

    .

    : , .

  19. #19
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    , . ?
    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|

  20. #20
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    - , , .

  21. #21
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    , , , . , , . , , /++.

    , , .
    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|

  22. #22
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    , , . , , .

  23. #23
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    , ,
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

  24. #24
    Registered User fly's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 803
    http://flyier.hit.bg/main.txt

    STABLE, *child , *parent ...

  25. #25
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    - - .
    , "" (*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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |