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

  • SEARCH
  • Home
  • 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 836043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:55:07+00:00 2026-05-15T04:55:07+00:00

I am trying to find the location of an element in the array. I

  • 0

I am trying to find the location of an element in the array.
I have tried to use this code i generated

for(i=0;i<10;i++)
    {
    if (strcmp(temp[0],varptr[i])==0) j=i;
    }

varptr is a pointer which points to array var[11][10] and it is by the definition *varptr[11][10]. I have assigned strings to var[i] and i want to get the “i” number of my element NOT THE ADRESS.

Thanks for any comment.

EDit: temp is also a pointer which points to the string that i want to check. Also i am using the 2D array for keeping variable names and their address. So yes i want to keep it inside a 2D array. The question is this code is not working at all, it does not assigns i to j, so i wonder where is the problem with this idea? writing a “break” does not change if the code works or not, it just optimizes the code a little.

Full Code:

#include <stdio.h>
#include <string.h>
#include <ctype.h>

double atof(char*);
int main(void)
{
    char in[100], *temp[10],var[11][10],*varptr[11][10];
    int i,j, n = 0,fullval=0;
    double val[11];
    strcpy(var[11], "ans");
    for(i=0;i<11;i++)
    {
        for(j=0;j<10;j++) varptr[i][j]=&var[i][j];
    }
START:
    printf("Enter the expression: ");
    fflush(stdout);
    for(i=0;i<10;i++) temp[i]=NULL;

    if (fgets(in, sizeof in, stdin) != NULL)
    {
        temp[0] = strtok(in, " ");

        if (temp[0] != NULL)
        {
            for (n = 1; n < 10 && (temp[n] = strtok(NULL," ")) != NULL; n++)
                ;
        }
        if (*temp[0]=="quit")
        {
            goto FINISH;}

        if (isdigit(*temp[0]))
        {

            if (*temp[1]=='+') val[0] = atof(temp[0])+atof(temp[2]);
            else if (*temp[1]=='-') val[0] = atof(temp[0])-atof(temp[2]);
            else if (*temp[1]=='*') val[0] = atof(temp[0])*atof(temp[2]);
            else if (*temp[1]=='/') val[0] = atof(temp[0])/atof(temp[2]);
            printf("%s = %f\n",var[11],val[0]);
            goto START;

        }
        else
            if (temp[1]==NULL) //asking the value of a variable
            {
            for(i=0;i<10;i++)
            {
            if (strcmp(temp[0],varptr[i])==0) j=i;
            }
            printf("%s = %d\n",var[j],val[j]);
            goto START;
            }
            if (*temp[1]==61)
            {
            strcpy(var[fullval], temp[0]);
            if ((temp[3])!=NULL)
            {
            }
            val[fullval]=atof(temp[2]);
            printf("%s = %f\n",var[fullval],val[fullval]);
            fullval++;
            goto START;
            }
            if (*temp[1]!=61)
            {


            }

    }
    getch();
FINISH:
    return 0;


}
  • 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-15T04:55:08+00:00Added an answer on May 15, 2026 at 4:55 am

    One comment: you can exit the loop as soon as you find your string.

    #define NOT_FOUND (-1)
    
    int j = NOT_FOUND;
    int i;
    for (i = 0 ; i < 11 && j == NOT_FOUND; i++)
    {
        if (strncmp(temp,var[i], 10) == 0) // Nick D's comment
        {
            j = i;
        }
    }
    

    Another comment:

    I was unable to understand how varptr and var relate to each other (please show definitions). I have used var in the above on the assumption it is defined:

    char var[11][10];
    

    also

    char temp[10];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find current location, and this is my code. LocationManager mlocManager
I have been trying to find the location of a module but can't I
Trying to find out if it's possible to use SQLAlchemy on Heroku. Thanks.
I have a component that changes its location based on other elements. I'm trying
I'm trying to trigger a click event on a dynamically created element. I have
I am trying to find a way to determine the location of the config
i looked everywhere trying to find an answer to this question. i want my
I have created this jsfiddle: http://jsfiddle.net/mfnxm/1/ I am trying to create this JSON: [{
I'm trying to find an element from a kml file using element trees as
i'm trying to write some dynamic code and i can't be sure the element

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.