Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,988 questions

51,933 answers

573 users

How to find the duplicate strings in a 2d string array with C

1 Answer

0 votes
#include <stdio.h> 

int main(void)
{
    char stringarray[][64] = {"C programming language",
        "General-purpose programming language",
        "C programming language",
        "Operating systems code",
        "Kernels, device drivers",
        "C23 - GCC, Clang, Intel C, C++ Builder, Microsoft Visual C++",
        "Operating systems code",
    };
    int size = sizeof(stringarray) / sizeof(stringarray[0]);


    for (int i = 0; i < size; i++) {
        for (int j = i + 1; j < size; j++) {
            // int strcmp (const char* str1, const char* str2);
            if (strcmp(stringarray[i], stringarray[j]) == 0) {
                printf("line %d and line %d: %s\n", i, j, stringarray[i]);
            }
        }
    }

    return 0;
}



/*
run:

line 0 and line 2: C programming language
line 3 and line 6: Operating systems code

*/

 



answered Jul 6, 2024 by avibootz
...