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 6584339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:31:29+00:00 2026-05-25T16:31:29+00:00

How would i implement this?Im trying to compare a array of c strings to

  • 0

How would i implement this?Im trying to compare a array of c strings to a single string and if there is no match append it to the 2d array.

char*mprt,uni[100][16];
    mprt = &uni[0][0];
for (int s = 0;s <= 99;s++)
        {
            for (int z = 0;z <= 15;z++)
            {
                if (strcmp(mprt++, string1) != 0)
                {
                    uni[s][z] = string1[z];
                }
            }
        }
  • 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-25T16:31:29+00:00Added an answer on May 25, 2026 at 4:31 pm

    Ok … from your comments I now get what you’re trying to do. You’d want to make this into a function so you could feed words to it, but it should get you pointed in the right direction.

    Note that you can use char[][], but this way your strings can be of any length because we dynamically allocate them when we put them in the list.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    int main()
    {
    
        /* space for 100 strings */
        char **uni = calloc(100, sizeof(char*));
        char **i;
    
        /* Put one word in the list for test */
        *uni = calloc(5, sizeof(char*));
        strncpy(*uni, "this", 5);
    
        /* here's the string we're going to search for */
        char * str2 = "that";
    
        /* go through the first dimension looking for the string 
           note we have to check that we don't exceed our list size */
        for (i = uni; *i != NULL && i < uni+100; i++)
        {
            /* if we find it, break */
            if (strcmp(*i,str2) == 0)
                break;
        }
    
        /* if we didn't find the string, *i will be null 
         * or we will have hit the end of our first dimension */
       if (i == uni  + 100)
       {
            printf("No more space!\n");
       }        
       else if (*i == NULL)
       {
            /* allocate space for our string */
            *i = calloc(strlen(str2) + 1, sizeof(char));
    
            /* copy our new string into the list */
            strncpy(*i, str2, strlen(str2) + 1);
        }
    
    
        /* output to confirm it worked */
        for (i = uni; *i != NULL && i < uni+100; i++)
            printf("%s\n",*i);
    }
    

    For completeness, the char[][] version:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    int main()
    {
    
        char uni[100][16];
        int i,j;
    
        /* init our arrays */
        for (i=0;i<100;i++)
            for (j=0;j<16;j++)
                uni[i][j] = '\0';
    
    
        /* Put one word in the list for test */
        strncpy(uni[0], "this",15);
    
        /* here's the string we're going to search for */
        char * str2 = "that";
    
        /* go through the first dimension looking for the string */
        for (i = 0; uni[i][0] != '\0'  && i < 100; i++)
        {
            /* if we find it, break */
            if (strcmp(uni[i],str2) == 0)
                break;
        }
    
        /* if we didn't find the string, uni[i][0] will be '\0'
         * or we will have hit the end of our first dimension */
        if (i == 100)
        {
            printf("No more space!\n");
        }
        else if (uni[i][0] == '\0')
        {
            /* copy our new string into the array */
            strncpy(uni[i], str2, 15);
        }
    
        /* output to confirm it worked */
        for (i = 0; uni[i][0] != '\0' && i < 100; i++)
            printf("%s\n",uni[i]);
    }
    

    Edit to explain C pointers and arrays from comments below:

    In C, arrays degrade to pointers. This is actually really confusing when you first start.

    If I have char myArray[10] and I want to pass that to a function that takes a char * argument, I can use either &myArray[0] or just myArray. When you leave off the index, it degrades to a pointer to the first element in the array.

    In a multidimensional array like yours, &uni[5][0] == uni[5] – both are pointers to the first element in the second dimension at index 5 in the first. It degrades to char* pointed at the beginning of the 6th word in your list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement this simple example in JSF: There is a user.xhtml page
I would like to implement a map simmilar to this: http://gmaps-utility-library.googlecode.com/svn/trunk/markerclusterer/1.0/examples/advanced_example.html One of the
I have this piece of logic I would like to implement as a trigger,
I would like to implement a command line interface for a Java application. This
How would I implement a binary search using just an array?
public abstract class MyAbs implements Comparable<MyAbs> This would work but then I would be
I handle commands inside a RoutedCommand class that implements RoutedUICommand. This would help me
In java <1.5, constants would be implemented like this public class MyClass { public
Recently I've been thinking about finite state machines (FSMs), and how I would implement
How would you implement a system with the following objectives: Manage authentication, authorization for

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.