C Programming. Comparing an array's contents. -


i have array result of program's input:

//1.

int i, numberofoccurances;     for(i = 0; < numofoccurrances; i++) {       printf("%d",printoccurrances[i]);    } 

and example output:

121 

now want compare array can print additional statement, example:

//2.

if (printoccurrances == 121) {     printf("this means blah"); } else if (printoccurrances == 232) {     printf("this means else"); } 

//what type of variable should set , how should set @ point 1? //what type of string statement should have @ point 2.

thanks assistance.

make comparison function , use compound literals @ call site:

#include <stdbool.h>  bool int_arr_cmp_n(int const * a, int const * b, size_t len) {     while (len--)         if (*a++ != *b++)             return false;     return true; } 

usage:

if (int_arr_cmp_n(printoccurrances, (int[]){1,2,1}, 3)) { /* ... */ } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -