what does"%c" mean in c and how can i convert it to c++????

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baroon
    New Member
    • Jan 2007
    • 12

    what does"%c" mean in c and how can i convert it to c++????

    pleaaeaeaeaese quick before wednesday


    what does"%c" mean in c and how can i convert it to c++????
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    I assume you mean in a printf statement. In such a location it means that the data has a value that is a printable character and should be output as a character rather than a number, this code should illustrate it

    Code:
    int main(int argc, char **argp)
    {
        char c = 'A';  /* Assign c the value of the character constant 'A' */
    
        /* Print c as a character and as a number */
        printf("'%c' = %d\n", c, c);
    
        return 0;
    }
    The variable c is output via printf as both a number and a printable character.

    The C++ equivalent is

    Code:
    #include "iostream"
    
    using namespace std;
    
    int main(int argc, char **argp)
    {
        char c = 'A';  /* Assign c the value of the character constant 'A' */
    
        cout << "'" << c << "' = " << (int)c << endl;
    
        return 0;
    }

    Comment

    • willakawill
      Top Contributor
      • Oct 2006
      • 1646

      #3
      Originally posted by baroon
      pleaaeaeaeaese quick before wednesday


      what does"%c" mean in c and how can i convert it to c++????
      This can also be used in c++

      Code:
      char c = 'A'
      char message[20];
      
      sprintf_s(message, 20, "c char: %c\nc int: %d", c, c);
      cout << message << endl;

      Comment

      • baroon
        New Member
        • Jan 2007
        • 12

        #4
        thaaaaanxxxxxxx xxxxxx very much my friend for help but i hahe something also to help
        i have programe and i need someone to change it from c to c++ .please i should finish it befor tuesday please,,,,,,,,t his is the programe


        _______________ _______________ _______________ _______________ ____

        /* Problem 0: Write a paragraph read from a file to the screen
        in a justified format, paragraph should end with . */

        /* Include libraries */
        #include <stdio.h>
        #include <string.h>


        int i,j;
        char temp1[1000];
        FILE *in;

        /* Excution Of Main Program Starts Here */
        int main ()
        {

        /* Open and Read from input file */
        in = fopen ("indata.dat"," r");
        if (in == NULL)
        {

        /* In case the file name does not exist, the following error
        /* message will be displayed */

        printf("Error : Couldn't open file indata.dat for reading...\n");
        printf("Error : File does not exist... \n");
        return 0;
        }
        else
        {


        /* Reading the pharagraph from file and print it in a justified mode */


        printf("\n The Justified Pharagraph is >> \n\n");
        fscanf(in,"%[^.].",&temp1);


        j=0;
        while (j<500)
        {
        label_start:
        printf("\n ");
        for (i=j+1; i<=j+60; i++)
        {
        if (temp1[i] == '.')
        goto label_end;

        if (temp1[i] == '\n')
        {
        j=i;
        goto label_start;
        }
        printf("%c",tem p1[i]);
        }
        j=j+60;
        }

        label_end:
        fclose(in);

        printf("\n---------------------------------------------------------\n");
        printf(" Thank You For Using My Program \n");
        printf(" Have A Nice Day \n");
        printf("---------------------------------------------------------\n");
        getchar();
        return 1;
        }}

        _______________ _______________ _______________ _________
        the program take the paragraph which want to justified from (txt.) for example
        the paragraph is ( This is program homework to be done in C++ language for the Clanguage course,it is realy interesting course which I have enjoied it alot :)
        I like programing languages...) . and the out put should be in the black screen :)

        Comment

        Working...