LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2005, 04:35 PM   #1
thanhVic
LQ Newbie
 
Registered: Jan 2005
Location: Canada
Distribution: Fedora3
Posts: 26

Rep: Reputation: 15
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
 
Old 04-04-2005, 04:49 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
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;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C pointers confusion - char ** = char [][] ?? saravkrish Programming 12 12-02-2004 10:06 AM
C Problem---convert char to char* totti10 Programming 11 11-06-2004 11:32 AM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 03:07 PM
convert from char* to unsigned char* D J Linux - Software 2 02-20-2004 04:09 AM
Copy a char* to another char* sathyan Programming 8 07-24-2003 06:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration