Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void giocatori(char *gioc1,char *gioc2){
  6.     char c;
  7.     char *tmp;
  8.     int dim=0;
  9.     printf("Inserisci il tuo nickname Giocatore 1 \n");
  10.     do{
  11.         c=getchar();
  12.         if(c!='\n') {
  13.             tmp=malloc(sizeof(char)*dim);
  14.             strcpy(tmp,gioc1);
  15.             dim++;
  16.             gioc1=malloc(sizeof(char)*dim);
  17.             strcpy(gioc1,tmp);
  18.             gioc1[dim-1]=c;
  19.             free(tmp);
  20.         }
  21.     }while(c!='\n');
  22.     gioc1[dim]='\0';
  23.     printf("%s",gioc1);
  24. }
  25.  
  26. int main() {
  27.     char giocatore1[1];
  28.     char *giocatore2;
  29.     giocatori(giocatore1,giocatore2);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement