Stringhe

Esercizi sulle stringhe

12/11/2021

211112-028_Cognome_Nome.c

Emulare la funzione: strcpy(s1, s2) Copia s2 in s1. visualizzare le 2 stringhe.
Copiato!
#include <stdio.h>
#include <string.h>
#define DIM 80
void my_strcpy(char [], char []);

int main(){
	char s1[DIM], s2[DIM];
	printf("prima stringa: ");
	gets(s1);
	fflush(stdin);
	my_strcpy(s2, s1);
	putchar('\n');
	puts(s2);
	return 0;
}

void my_strcpy(char s2[], char s1[]){
	int i;
	i=0;
	while(s1[i]!='\0'){
		s2[i]=s1[i];
		i++;
	}
	s2[i]='\0';
}