Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6094755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:43:01+00:00 2026-05-23T12:43:01+00:00

In C programming, how do i check whether char array[] contains int , float

  • 0

In C programming, how do i check whether char array[] contains int, float or double value and also store the value using respective data type?

Example:
If the char array[] contains 100 – its int value and should be store in int a.
if the char array contains 10000.01 its float value and should be stored in float b.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:43:01+00:00Added an answer on May 23, 2026 at 12:43 pm

    The only way you can store mixed types in an array is to have an array of pointers.

    You’d need to use a struct or a union to store each one too like so:

    #define TYPE_INT 1
    #define TYPE_FLOAT 2
    #define TYPE_STRING 3
    
    typedef struct  {
      int type;
      void *ptr;
    } object;
    
    object* mkobject( int type, void * data ){
      object * obj = (object*)malloc(COUNT*sizeof(object))
      obj->type = type;
      obj->ptr = data;
      return obj;
    }
    

    No using the above you can store type information

    void * intdup( int original ) {
      int * copy = (int*) malloc(1*sizeof(int));
      *copy = original; 
      return (void*) copy;
    }
    
    void * floatdup( float original ) {
      float * copy = (float*) malloc(1*sizeof(float));
      *copy = original; 
      return (void*) copy;
    }
    
    int COUNT = 3;
    objects** objectlist = (object**)malloc(COUNT*sizeof(object*))
    
    // -- add things to the list
    int a_number = 2243;
    float a_float = 1.24;
    char* a_string = "hello world"; 
    
    
    objectlist[0] = mkobject( TYPE_STRING, strdup(a_string) );
    objectlist[1] = mkobject( TYPE_INT, intdup(a_number) );
    objectlist[2] = mkobject( TYPE_FLOAT, intdup(a_float) );
    
    
    // iterate through a list
    
    for ( int x = 0; x < COUNT; x++ ){
    
       switch( objectlist[x]->type ){
    
          case TYPE_STRING:
           printf("string [%s]\n",(char*) objectlist[x]->ptr );
           break;
          case TYPE_FLOAT:
           printf("float  [%f]\n", *(float*) objectlist[x]->ptr );
           break;
          case TYPE_INT:
           printf("int    [%d]\n", *(int*) objectlist[x]->ptr );
           break;
          default;
           printf("unintialized object\n");
           break;
    
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When programming by contract a function or method first checks whether its preconditions are
Quite often, in programming we get situations where null checks show up in particularly
Programming Student here...trying to work on a project but I'm stuck. The project is
Programming in vim I often go search for something, yank it, then go back
Programming languages had several (r)evolutionary steps in their history. Some people argue that model-driven
Programming PHP in Eclipse PDT is predominately a joy: code completion, templates, method jumping,
Programming is learned by writing programs. But code reading is said to be another
Some programming languages such as Java and C# include encryption packages in their standard
different programming languages have different features or lack certain features. Design patterns are a
Functional programming seems to be a paradigm in computer science which has more and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.