bonjour,
je me lance dans ce langage que je ne trouve pas super simple...
en faisant des exercices, je tombe sur un os.
il s'agit de saisir une recherche de livre par auteur ou par titre.
je veux faire saisir une chaine avec un fgets mais je récupère le retour chariot et ne peux comparer mes chaines, quelqu'un aurait-il une solution simple ?

dans le main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
NSString *typeRech;
NSString *chaineRech;
NSMutableArray *listeLivres=[NSMutableArray new];
char inputbuffer[200];
//ma bibliothèque
BookStore* theBookNook = [[BookStore alloc] init];
//saisir le type de recherche
fgets(inputbuffer, 10,stdin);
typeRech=[[[NSString alloc] initWithUTF8String:inputbuffer]uppercaseString];
//saisir le titre du livre
fgets(inputbuffer, 200, stdin);
chaineRech=[[NSString alloc] initWithUTF8String:inputbuffer];
[theBookNook findBookWithString:chaineRech ofType:typeRech inArray:listeLivres];
dans la fonction findBookWithString:ofType:inArray:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
- (void)findBookWithString:(NSString *)whichString 
				  ofType:(NSString *)newType
				 inArray:(NSMutableArray *)myList{
	Book *book;	
	//je compare si c'est une recherche par auteur
	if ([newType isEqualToString:@"AUTEUR"]) {
           //je parcours ma bibliothèque
		for (NSString * key in myBookStore) {
			book=[myBookStore objectForKey:key];
                       //si c'est le même auteur je le rajoute à mon tableau
			if ([book.author isEqualToString:whichString]) {
				[myList addObject:book];
			}
		}
	}else {
                //si c'est une recherche par titre, je recherche la clé
		book=[myBookStore objectForKey:whichString];
		if (book != nil) {
				[myList addObject:book];
		}		
	}
}