Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 05.12.2014, 23:49   #1
orandzheviyman
Пользователь
 
Регистрация: 11.11.2013
Сообщений: 74
По умолчанию Проблема со считыванием строки

Код:
Код:
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <vector>


using namespace std; 
struct ORDER {
	char* plat [7];
	char* poluch [7];
	int summa;
	ORDER *next;
			 };

void Read_in_Line_list ();
void add (ORDER &temp);
void Print_Line_list ();
void Make_arrays ();
void Print_arrays ();
//int Sravnenie_plat (ORDER* elem);
//int Sravnenie_poluch (ORDER* elem);
void Search_line ();

ORDER *pHead, *pCurrent = 0;
vector <ORDER*> mass1, mass2;
 
int count, m = 0;

			
main (){
	Read_in_Line_list ();
	Print_Line_list();
	cout<< "Kolichestvo zapisey="<<count<<endl;
	Make_arrays ();
	Print_arrays ();
	Search_line ();
	getch();
}
	
	
void Read_in_Line_list (){
	FILE *f;
	ORDER temp;
	char namefile[50];
	cout<<"Vvedite imya faila:  ";
	cin>>(namefile);
 	f = fopen (namefile, "r");
 	while (!feof(f)){
 		fscanf(f,"%s\t%s\t%d\n",&temp.plat,&temp.poluch,&temp.summa);
		add(temp);
 		count++;
 	}
}

void add (ORDER &temp){
	ORDER *addt = new ORDER;
	*addt=temp;
	if (pHead == 0){
		pHead = addt;
		pCurrent = addt;}
			else{
				pCurrent->next = addt;
				pCurrent = addt;
				}				
	}

void Print_Line_list (){
	printf ("#Plat\t\t#Poluch\t\tSumma\n");
	pCurrent = pHead;
		for (int i=0; i<count; i++){
	//	while (pCurrent){
		//cout<< *pCurrent->plat, *pCurrent->poluch, pCurrent->summa;
		printf ("%s\t%s\t%d\n",pCurrent->plat,pCurrent->poluch,pCurrent->summa);
		pCurrent=pCurrent->next;
							//		}
                                   }

}

void Make_arrays (){
	pCurrent = pHead;
	for (int i = 0; i <count; i++){
		mass1.push_back(pCurrent);
		mass2.push_back(pCurrent);
		pCurrent = pCurrent->next;
	}
}

void Print_arrays (){
		for (int i = 0; i <count; i++){
			printf ("%s\t%s\t%d\n",mass1[i]->plat,mass1[i]->poluch,mass1[i]->summa);
			printf ("%s\t%s\t%d\n",mass2[i]->plat,mass2[i]->poluch,mass2[i]->summa);
		}
}

void Search_line () {
	int detectU = 0, detectNU = 0;
	char*isk_plat[7];;
	char* isk_poluch[7];
	int isk_summa = 0;
		
	cout<< "Choose key search"<<endl;
	cout<< "1 - #Plat"<<endl;
	cout<< "2 - #Poluch"<<endl;
	cout<< "3 - Summa"<<endl;
	cout<< "Your choise is - ";
	cin>>m;
	switch (m){
		case 1:{
			cout<<"Vvedite iskomiy #Plat: ";
			scanf ("%s", &isk_plat);
			for (int i = 0; (i <count && detectU!=1); i++){
				if (strcmp(*mass1[i]->plat, *isk_plat) == 0){
					printf ("%s\t%s\t%d\n",*mass1[i]->plat,mass1[i]->poluch,mass1[i]->summa);
					detectU = 1;
				}
			}
		break;
		}
		case 2:{
			cout<<"Vvedite iskomiy #Poluch: ";
			scanf ("%s", &isk_poluch);
			for (int i = 0; (i <count && detectU!=1); i++){
				if (strcmp(*mass1[i]->poluch, *isk_poluch) == 0){
					printf ("%s\t%s\t%d\n",mass1[i]->plat,mass1[i]->poluch,mass1[i]->summa);
					detectU = 1;
				}
			}
			break;
		}
		case 3:{
			cout<<"Vvedite iskomuyu summu: ";
			//scanf ("%s", &isk_summa);
			cin>>isk_summa;
			for (int i = 0; i <count; i++){
				if (mass1[i]->summa == isk_summa){
					printf ("%s\t%s\t%d",mass1[i]->plat,mass1[i]->poluch,mass1[i]->summa);
					detectNU = 1;	
				}
			} 
			break;
		}
	}
	if ((detectU || detectNU) != 1)
		cout<<"Not found :(";
}








/*int Sravnenie_plat (ORDER* elem){
	printf ("%s\t%s\t", elem->plat, isk_plat);
	if (!strcmp (*elem->plat, *isk_plat))
		return 1; //true
	return 0;  //false
}*/

/*int Sravnenie_poluch (ORDER* elem){
	if (!strcmp (*elem->poluch, *isk_poluch))
		return 1; //true
	return 0;  //false
}*/
Нужно считать данные из файла, занести их в однонаправленный список, составить два массива указателей на элементы списка и реализовать линейный поиск с помощью массивов (ручками). Определил проблему со считыванием строки в переменную для поиска. Помогите, пожалуйста.
В комментариях есть то, как я пытался реализовать поиск с помощью функционального типа, но не разобрался до конца и забросил
orandzheviyman вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Проблема со считыванием файла в delphi aftio Помощь студентам 20 13.05.2012 23:16
Проблема со считыванием файла в delphi aftio Общие вопросы Delphi 2 07.05.2012 16:38
Проблема с считыванием данных из файла Achervov Общие вопросы C/C++ 4 19.03.2012 09:24
проблема из считыванием записи структуры из файла bloger Общие вопросы C/C++ 0 07.12.2011 22:25
Проблема считыванием данных из файла(fortran 90) ivan.tiran Помощь студентам 0 03.11.2011 22:46