LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   char to char* (https://www.linuxquestions.org/questions/programming-9/char-to-char%2A-309712/)

thanhVic 04-04-2005 04:35 PM

char to char*
 
Hi, my program is written in C

Code:

#include <stdio.h>
int main(int argc, char *argv[])
{
        char in;
        /* Read from Standard input */
        do
        {
                in = fgetc(stdin);
                printf ("%c",in);
        } while ( in != EOF);

        return 0;
}


As you can see, the variable "in" is a char type. How can I convert it to a string ?? I tried
Code:

char* new = (char*)in;
but it seems not to work.

Please help me,

Thanks

jim mcnamara 04-04-2005 04:49 PM

Code:

#include <stdio.h>
int main(int argc, char *argv[])
{
        int in;  /* this has to be an int to handle EOF */
        char string[64]={0x0};
        int i=0;
        /* Read from Standard input */
        do
        {
                in = fgetc(stdin);
                printf ("%c",in);
                string[i++]=in;
        } while ( in != EOF && i < 64 );
        return 0;
}



All times are GMT -5. The time now is 04:24 PM.