• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

C array doubt== Urgent

Hello experts,

            I am stuck in  a situation here, more due to my inexperience in c.

I have two API functions . The first API function wll return a certain number of names.
I have to apply the second function on these names. This second function will give me back whether
there are nick names for that name ( true-if nick name exist; false-if nick nick doesn't exist)
So I wnat back those names which has a nick name........

I have some idea , please check whther it will work

array 1 ==> get the values from function1

on each value on array1 apply function2

return those values for whcih function2 returns true....

If this will work, please give me the code for this one.......

If not provide me another logic.......
Code snippets are greatly preferred.Early responses are greatly appreciated

Thanks in Advance

  • 2
1 Solution
bool nick[sizeof(array1)/sizeof(array1[0])]; //basically number of elements
i think you would prefer to declare it as bool nick[PREDEFINED_SIZE];

void function2(bool nick[], int num){
  for (i=0; i<num; i++)
      nick[i] = true;
    else nick[i] = false;

i don't know where your names are stored so i can't help you with function1.

Declare an array of pointers and fill it with those entries in the actual array which have corresponding nick names. Return this array
Something to the tune of

char ** my_func ( )
          char * names[MAX] = { 0 };
          char * nicks [MAX] = { 0 };
          int i,j;

          //allocate memory for each element of names[] - TODO
         // call function_1 and get the names array populated - TODO

           for ( i=0,j=0; i<MAX; i++ )
                    if ( function_2 ( names[i] ) )
                             nicks[j] = names[i];
            return nicks;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The Lifecycle Approach to Managing Security Policy

Managing application connectivity and security policies can be achieved more effectively when following a framework that automates repeatable processes and ensures that the right activities are performed in the right order.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now