Compare commits
	
		
			No commits in common. "9d08631b32eff42d9622eaf4ea66a81ccbac16ef" and "a1f8b096e37150e9f268b4f07cb3e776d68dac1b" have entirely different histories.
		
	
	
		
			9d08631b32
			...
			a1f8b096e3
		
	
		
							
								
								
									
										1
									
								
								code/C/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								code/C/.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,2 +1 @@
 | 
			
		||||
fgets-simple
 | 
			
		||||
demo-strtok
 | 
			
		||||
 | 
			
		||||
@ -2,8 +2,6 @@
 | 
			
		||||
# exemples pour le chapitre sur le C
 | 
			
		||||
# new Sat Feb 11 12:06:34 CET 2023
 | 
			
		||||
 | 
			
		||||
all:	no-op slowprint fgets-simple
 | 
			
		||||
 | 
			
		||||
no-op:			no-op.c Makefile
 | 
			
		||||
	gcc -Wall $< -o $@
 | 
			
		||||
 | 
			
		||||
@ -13,5 +11,3 @@ slowprint:		slowprint.c Makefile
 | 
			
		||||
fgets-simple:		fgets-simple.c Makefile
 | 
			
		||||
	gcc -Wall $< -o $@
 | 
			
		||||
 | 
			
		||||
demo-strtok:		demo-strtok.c Makefile
 | 
			
		||||
	gcc -Wall $< -o $@
 | 
			
		||||
 | 
			
		||||
@ -1,52 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 *	demo strtok 
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include   <stdio.h>
 | 
			
		||||
#include   <string.h>
 | 
			
		||||
#include   <ctype.h>
 | 
			
		||||
/*---------------------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
void dump_line(char *titre, char *ligne, int combien)
 | 
			
		||||
{
 | 
			
		||||
int		foo;
 | 
			
		||||
unsigned char	*ptr;
 | 
			
		||||
 | 
			
		||||
printf("   --- %s\n", titre);
 | 
			
		||||
ptr = (unsigned char *)ligne;
 | 
			
		||||
for (foo=0; foo<combien; foo++) {
 | 
			
		||||
	printf("%02x ", ptr[foo]);
 | 
			
		||||
	}
 | 
			
		||||
puts("");
 | 
			
		||||
for (foo=0; foo<combien; foo++) {
 | 
			
		||||
	printf(" %c ", isprint(ptr[foo]) ? ptr[foo] : '?');
 | 
			
		||||
	}
 | 
			
		||||
puts("");
 | 
			
		||||
}
 | 
			
		||||
/*---------------------------------------------------------------------*/
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
char		input[] = "foo bar quux quiz";
 | 
			
		||||
char		*cptr, *copie;
 | 
			
		||||
int		foo;
 | 
			
		||||
 | 
			
		||||
dump_line("original", input, sizeof(input));
 | 
			
		||||
copie = strdup(input);
 | 
			
		||||
dump_line("copie", copie, sizeof(input));
 | 
			
		||||
puts("");
 | 
			
		||||
 | 
			
		||||
cptr = strtok(copie, " \t");
 | 
			
		||||
dump_line("1er strtok", copie, sizeof(input));
 | 
			
		||||
printf("   got [%s]\n", cptr);
 | 
			
		||||
puts("");
 | 
			
		||||
 | 
			
		||||
cptr = strtok(NULL, " \t");
 | 
			
		||||
cptr = strtok(NULL, " \t");
 | 
			
		||||
dump_line("2eme & 3me strtok", copie, sizeof(input));
 | 
			
		||||
foo = cptr - copie;
 | 
			
		||||
printf("   index = %d\n", foo);
 | 
			
		||||
printf("   and we have [%s]\n", input+foo);
 | 
			
		||||
return 0;
 | 
			
		||||
}
 | 
			
		||||
/*---------------------------------------------------------------------*/
 | 
			
		||||
@ -1,14 +1,14 @@
 | 
			
		||||
/*
 | 
			
		||||
 *		exemple d'utilisation de 'fgets'
 | 
			
		||||
 *		exemple utilisation 'fgets'
 | 
			
		||||
 */
 | 
			
		||||
#include  <stdio.h>
 | 
			
		||||
#include  <string.h>
 | 
			
		||||
#define		TL	12
 | 
			
		||||
#define		TL	8
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
char		buffer[TL+1];
 | 
			
		||||
while( fgets(buffer, TL, stdin) ) {
 | 
			
		||||
	printf("   %4ld      %s\n", strlen(buffer), buffer);
 | 
			
		||||
	printf("   %4ld\n", strlen(buffer));
 | 
			
		||||
	}
 | 
			
		||||
return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -11,21 +11,19 @@
 | 
			
		||||
#include  <arpa/inet.h>
 | 
			
		||||
 | 
			
		||||
#define BINDADDR	"127.0.0.1"
 | 
			
		||||
#define BINDPORT	5678
 | 
			
		||||
 | 
			
		||||
#define TL		20		/* important value */
 | 
			
		||||
#define TL		20
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
int			foo, len, sock;
 | 
			
		||||
char			*adr_ip = BINDADDR;
 | 
			
		||||
int			port     = BINDPORT;
 | 
			
		||||
int			port = 5678;
 | 
			
		||||
unsigned int		addrlen;
 | 
			
		||||
int			connected;
 | 
			
		||||
struct sockaddr_in	addr;
 | 
			
		||||
struct in_addr		ia;
 | 
			
		||||
FILE			*fpin;
 | 
			
		||||
char			line[TL+5];
 | 
			
		||||
char			line[TL+5], *ptr;
 | 
			
		||||
 | 
			
		||||
fprintf(stderr, "--- %s ---\n", argv[0]);
 | 
			
		||||
 | 
			
		||||
@ -73,7 +71,7 @@ for (;;) {
 | 
			
		||||
		}
 | 
			
		||||
	// fprintf(stderr, "fopened...\n");
 | 
			
		||||
 | 
			
		||||
	while ( fgets(line, TL, fpin) ) {
 | 
			
		||||
	while ( (ptr=fgets(line, TL, fpin)) ) {
 | 
			
		||||
		len = strlen(line);
 | 
			
		||||
		fprintf(stderr, "   %3d  |  %s", len, line);
 | 
			
		||||
		for (foo=0; foo<len; foo++) {
 | 
			
		||||
@ -81,8 +79,7 @@ for (;;) {
 | 
			
		||||
			}
 | 
			
		||||
		fputs("\n", fpin);
 | 
			
		||||
		}
 | 
			
		||||
	fclose(fpin);
 | 
			
		||||
	// close(connected);
 | 
			
		||||
	close(connected);
 | 
			
		||||
	} /* end of the endless loop */
 | 
			
		||||
 | 
			
		||||
return 0;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user