Creato esercizio con stringhe - nome e cognome
This commit is contained in:
BIN
3.nome_cognome_string/nc
Executable file
BIN
3.nome_cognome_string/nc
Executable file
Binary file not shown.
80
3.nome_cognome_string/nc.c
Normal file
80
3.nome_cognome_string/nc.c
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main (int index, char** in_data){
|
||||||
|
|
||||||
|
char buf[100];
|
||||||
|
char bufn1[100];
|
||||||
|
char bufn2[100];
|
||||||
|
int num1,num2,sum;
|
||||||
|
|
||||||
|
|
||||||
|
fprintf (stdout,"Digitare 2 numeri separati da uno spazio\n");
|
||||||
|
fscanf (stdin, "%99[^\n]%*c",buf);
|
||||||
|
sscanf (buf,"%s %s", bufn1, bufn2);
|
||||||
|
num1 = atoi(bufn1);
|
||||||
|
num2 = atoi(bufn2);
|
||||||
|
sum = num1 + num2;
|
||||||
|
|
||||||
|
fprintf(stdout,"La somma e' %d\n", sum);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fprintf (stdout,"Digitare un nome\n");
|
||||||
|
fscanf (stdin, "%99[^\n]%*c",bufn1);
|
||||||
|
fprintf (stdout,"Digitare un cognome\n");
|
||||||
|
fscanf (stdin, "%99[^\n]",bufn2);
|
||||||
|
|
||||||
|
char bufsum[200];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
strcpy(bufsum, bufn1);
|
||||||
|
strcat(bufsum, "-");
|
||||||
|
strcat(bufsum, bufn2);
|
||||||
|
|
||||||
|
fprintf(stdout,"%s\n",bufsum);
|
||||||
|
|
||||||
|
|
||||||
|
strcpy(bufsum, bufn2);
|
||||||
|
strcat(bufsum, "-");
|
||||||
|
strcat(bufsum, bufn1);
|
||||||
|
fprintf(stdout,"%s\n",bufsum);
|
||||||
|
|
||||||
|
|
||||||
|
if (strcmp(bufn1,bufn2) == 0){
|
||||||
|
fprintf(stdout,"Stringhe uguali\n");
|
||||||
|
} else {
|
||||||
|
fprintf(stdout,"Stringhe diverse\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char iniziali[3];
|
||||||
|
iniziali[0] = bufn1[0];
|
||||||
|
iniziali[1] = bufn2[0];
|
||||||
|
iniziali[2] = 0;
|
||||||
|
|
||||||
|
|
||||||
|
fprintf(stdout,"Iniziali %s\n",iniziali);
|
||||||
|
|
||||||
|
char code[150];
|
||||||
|
char sumc[150];
|
||||||
|
sprintf (sumc,"%d",sum);
|
||||||
|
|
||||||
|
strcpy(code, iniziali);
|
||||||
|
strcat(code, sumc);
|
||||||
|
|
||||||
|
fprintf(stdout,"Codice %s\n",code);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
1
3.nome_cognome_string/readme.txt
Normal file
1
3.nome_cognome_string/readme.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
il programma legge in in input prima due numeri restituendo la somma, poi un nome e congome formando diverse concatenazioni
|
||||||
0
test/gino~
Executable file
0
test/gino~
Executable file
19
test/test.c
19
test/test.c
@@ -1,12 +1,25 @@
|
|||||||
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
int main (int index, char** in_data){
|
int main (int index, char** in_data){
|
||||||
|
|
||||||
char buf[50];
|
int fd;
|
||||||
fscanf(stdin,"%10[^\n]",buf);
|
int data;
|
||||||
fprintf(stdout,"%s",buf);
|
void * buf;
|
||||||
|
buf = malloc (100);
|
||||||
|
|
||||||
|
fd = open ("gino",O_WRONLY | O_APPEND,00700);
|
||||||
|
lseek (fd,2,SEEK_SET);
|
||||||
|
write (fd,(void *)"ehi",3);
|
||||||
|
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user