Created
September 26, 2012 21:39
-
-
Save travisperson/3790762 to your computer and use it in GitHub Desktop.
Storing both a double and a string in an array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdio.h> | |
#define STRING 1 | |
#define DOUBLE 2 | |
typedef struct _my_data | |
{ | |
int myDataType; | |
double myDouble; | |
char myString[20]; | |
} MyData; | |
int main () | |
{ | |
MyData data[2]; | |
int count = 0; | |
data[0].myDataType = STRING; | |
strcpy(data[0].myString, "This is a String"); | |
data[1].myDataType = DOUBLE; | |
data[1].myDouble = 1.0; | |
for ( count = 0; count < 2; count++ ) | |
{ | |
if ( data[count].myDataType == STRING ) | |
{ | |
printf("Its a string! %s\n", data[count].myString); | |
} | |
else if ( data[count].myDataType == DOUBLE ) | |
{ | |
printf("Its a double! %lf\n", data[count].myDouble); | |
} | |
else | |
{ | |
printf("I don't know what kind of data that is.\n"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting, whats this for?