Announcement

Collapse
No announcement yet.

Input Stringhe E Malloc

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Input Stringhe E Malloc

    PHP Code:
    #include <st***.h>
    #include <stdlib.h>


    int main (void) {
        
        
    int i,j;
        
    char array [100] ;
        
    char *vet_s[5];
        
    char *punt;
        
        for (
    j=0;j<5;j++){
        
            
    scanf("%99s",array); // stringhe input
            
            
    for (i=0;*(array +i)!=0;i++){ // conteggio caratteri stringa compreso 0
            
    }
            
            
    punt= (char * ) malloc ((i+1)*sizeof(char)); // allocazione spazio per la stringa
            
            
    for (i=0;*(array +i)!=0;i++){ // copia da buffer ad allocazione
                
    *(punt i)= *(array +i);
            }
            *(
    punt i)= *(array +i);
            
            *(
    vet_s j)= punt// array di stringhe di j punta alla string in input
        
    }
        
        
    printf("Stampa valori inseriti\n");
        
        for(
    i=0;i<5;i++){
            
    printf("%s\n",*(vet_s i));
        }

        return 
    0;

    | VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio
Working...
X

Google Profile


My name is Giovanni Di Grezia, but people call me xgiovio.

Here is my homepage:.

I'm a VFX Artist and Software Developer.

Giovanni Di Grezia