Разработка программы на языке C/С++, страница 8

stnamelineEdit->setText(codeform->stnamelineEdit->text());

}

delete codeform;

}

main.cpp

#include <qapplication.h>

#include "mainform.h"

int main( int argc, char ** argv )

{

    QApplication a( argc, argv );

    QTranslator translator( 0 );

    translator.load( "tt2_ru", "." );

    a.installTranslator( &translator );

    MainForm w;

    w.show();

    a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );

    return a.exec();

}

roadresolve.h

int openrresolvefile(const char *fname);

char *resolveroad(int roadcode);

int freerresolvedata(void);

struct roadresrec

{

  unsigned int rcode;

  char roadnam[60];

  struct roadresrec *next;

};

struct roadresrec *rresinfo,*rcurr;

char *resolveroad(int roadcode)

{

  rcurr=rresinfo;

  while (rcurr)

    {

      if (rcurr->rcode==roadcode)

                                                                                                                                                                                                                                   return (rcurr->roadnam);

      rcurr=rcurr->next;

    }

    return NULL;

}

int resolveroadcode(const char *roadname)

{

  rcurr=rresinfo;

  while (rcurr)

    {

      if (strncmp(rcurr->roadnam,roadname,50)==0)

                                                                                                                                                                                                                                             return (rcurr->rcode);

      rcurr=rcurr->next;

     }

    return NULL;

}                                                                                                                                                                                                                                          

/*

Ошибки:

 -1 проблемы с файлом

 -5 ошибка динамического выделения памяти

*/

int openrresolvefile(const char *fname)

{

  FILE *f=fopen(fname,"rt");

  if (f==NULL) return -1;

  rresinfo=(roadresrec*)malloc(sizeof(*rcurr));

  if (!rresinfo) return -5;

  rcurr=rresinfo;

  while (!feof(f))

    {

      fscanf(f,"%7lu",&rcurr->rcode);

      fscanf(f,"%s\n",rcurr->roadnam);

      if ((rcurr->next=(roadresrec*)malloc(sizeof(*rcurr)))==NULL) return -5;

      rcurr=rcurr->next;

    }

  fclose(f);

  }

int freerresolvedata(void)

{

  void *p;

  rcurr=rresinfo;

  while (rcurr)

    {

      p=rcurr->next;

      free(rcurr);

      rcurr=(roadresrec*)p;

    }

}

stresolve.h

int openresolvefile(const char *fname);

char *resolvestat(unsigned long int stcode);

unsigned long int resolvestcode(const char *stname);

int freeresolvedata(void);

struct strresrec

{

  unsigned int stcode;

  char stanam[60];

  struct strresrec *next;

};

struct strresrec *resinfo,*curr;

char *resolvestat(unsigned long int stcode)

{

  curr=resinfo;

  while (curr)

    {

      if (curr->stcode==stcode)

return (curr->stanam);

      curr=curr->next;

       }

    return NULL;

}

unsigned long int resolvestcode(const char *stname)

{

  curr=resinfo;

  while (curr)

    {

      if (strncmp(curr->stanam,stname,50)==0)

  return (curr->stcode);

      curr=curr->next;

     }

    return NULL;

}

/*

Ошибки:

 -1 проблемы с файлом

 -5 ошибка динамического выделения памяти

*/

int openresolvefile(const char *fname)

{

  FILE *f=fopen(fname,"rt");

  if (f==NULL) return -1;

  resinfo=(strresrec*)malloc(sizeof(*curr));

  if (!resinfo) return -5;

  curr=resinfo;

  while (!feof(f))

    {

      fscanf(f,"%7lu",&curr->stcode);

      fscanf(f,"%s\n",curr->stanam);

      if ((curr->next=(strresrec*)malloc(sizeof(*curr)))==NULL) return -5;

      curr=curr->next;

    }

  fclose(f);

  }

int freeresolvedata(void)

{

  void *p;

  curr=resinfo;

  while (curr)

    {

      p=curr->next;

      free(curr);

      curr=(strresrec*)p;

    }

}Приложение Б Скриншот окна программы

Рисунок 1 – Скриншот главного окна программы