Програма сортировки смс сообщений по отправителю/получателю виснет - C (СИ)

Узнай цену своей работы

Формулировка задачи:

Привет рограммное обеспечение должно принять файл, который сортирован по отправителю. И отсортировать его по имени получателя. Программа застревает . И я не понимаю, почему .
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
 
#define NAME 20
#define MSG  50
void Get_Lost(char* str);
int check_out(FILE* out, char* name);
void print_out_name(FILE* out,char* name);
 
void main(void)
{
    int i=0;
    int counter=0;
    int chek=0;
    char name[NAME];
    char oneline_in[80];
    FILE *in,*out;
 
    fopen_s(&in,"Message_By_Senders.txt","r");
    if(!in)
        Get_Lost("Can't open a input file");
    fopen_s(&out,"Message_By_Recivers.txt","w+");
    if(!out)
        Get_Lost("Can't open a output file");
 
        while ( fgets(oneline_in,80,in)!=NULL )     // take one by one lines from input
        {
            if ( strlen(oneline_in)<=20 )           // checking if is a massage line
                strcpy(name,oneline_in);
            else
            {
                i=0;
                while (oneline_in[i]!=' ')          // take a name from input line
                {
                    name[i]=oneline_in[i];
                    i++;
                }
                name[i]='\0';
                
                check_out(&out,name);           // check if a name is in output file
            }
        }
    fclose(in);
    fclose(out);
 
    system("PAUSE");
}
 
void Get_Lost(char* str)
{
    puts(str);
    system("PAUSE");
    exit(1);
}
 
int check_out(FILE* out, char* name)                    // check all lines 
{
    char one_line_out[80];
 
    while ( fgets(one_line_out,80,out)!=NULL )
    {
        if(strstr(one_line_out,name)==NULL)
        {
            print_out_name(&out,name);
            return 1;
        }
    }
        return 0;   
}
 
void print_out_name(FILE* out,char* name)       // print name to file
{
    fprintf(out,"%s",name);
}

Решение задачи: «Програма сортировки смс сообщений по отправителю/получателю виснет»

textual
Листинг программы
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
 
#define NAME 20
#define MSG  50
void Get_Lost(char* str);
 
void main(void)
{
    int i=0;
    int counter=0;
    int chek=0;
    char name[NAME];
    char oneline_in[80];
    char oneline_out[80];
    FILE *in,*out;
 
    fopen_s(&in,"Message_By_Senders.txt","r");
    if(!in)
        Get_Lost("Can't open a input file");
    fopen_s(&out,"Message_By_Recivers.txt","w+");
    if(!out)
        Get_Lost("Can't open a output file");
 
        while ( fgets(oneline_in,80,in)!=NULL ) // Take one line to check
        {
            if ( strlen(oneline_in)<=20 )       // If no massege in line 
                strcpy_s(name,strlen(oneline_in),oneline_in);       
            else
            {
                i=0;
                while (oneline_in[i]!=' ')
                {
                    name[i]=oneline_in[i];
                    i++;
                }
                name[i]='\0';
 
                if (feof(out))
                    fputs(name,out);
                else
                {
                    while ( fgets(oneline_out,80,out)!=NULL )
                        if(strstr(oneline_out,name)==NULL)
                            counter++;
                if(counter>0)
                {
                    printf("F L U G");
                    counter=0;
                }
                }
            }
            }   
    fclose(in);
    fclose(out);
 
    system("PAUSE");
}
 
void Get_Lost(char* str)
{
    puts(str);
    system("PAUSE");
    exit(1);
}

Оцени полезность:

9   голосов , оценка 4 из 5
Похожие ответы