Solved

C array doubt== Urgent

Posted on 2004-09-23
3
354 Views
Last Modified: 2010-04-15
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

Jango........
0
Comment
Question by:jango_ms
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:jhshukla
ID: 12131161
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++)
    if(nickname_if_found)
      nick[i] = true;
    else nick[i] = false;
}

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

jaydutt
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12131264
Declare an array of pointers and fill it with those entries in the actual array which have corresponding nick names. Return this array
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 250 total points
ID: 12131394
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];
                             j++;
                     }
            }
            return nicks;
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
libcurl - taking long time on curl_easy_perform 11 497
How to creat good software interface ? 1 76
Windows Server 2012 R2 - connect to computer 13 97
Reactjs with .NET 3 122
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question