Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to add user defined char and float in array so that the compiler can give the out put in a line

+2 votes
asked Jul 4, 2022 by Abbas Shaheer (140 points)

1 Answer

+1 vote
answered Jul 5, 2022 by Peter Minarik (86,040 points)

Use typedef to create your own types. The below C example should help:

#include <stdio.h>

typedef char myChar;
typedef float myFloat;

void main()
{
    // Scalars
    myChar ch = 'A';
    myFloat pi = 3.14f;
    printf("The first letter of the alphabet is '%c'.\n", ch);
    printf("The rounded value of PI is %.2f.\n", pi);
    // Arrays
    myFloat floats[10] = { 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8, 1.9, 2.0f };
    myChar myChars[13] = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\0' };
    printf("A float array: ");
    for (int i = 0; i < 10; i++)
    {
        if (i > 0)
            printf(", ");
        printf("%.2f", floats[i]);
    }
    printf("\nA character array: %s\n", myChars);
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...