How to use typedef for char * in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef char *StringP;

int main(void)
{
    StringP s;
    
    if ( (s = (StringP) malloc(16 * sizeof(char))) != NULL)
    {
        strcpy(s, "hello");
        puts(s);
        free(s);
    
    }
    
    return 0;
}


/*
run:
 
hello

*/

 



answered Dec 8, 2015 by avibootz

Related questions

1 answer 250 views
250 views asked Dec 6, 2015 by avibootz
1 answer 263 views
263 views asked Dec 29, 2021 by avibootz
1 answer 240 views
240 views asked May 7, 2021 by avibootz
3 answers 527 views
2 answers 307 views
307 views asked Aug 18, 2017 by avibootz
1 answer 318 views
...