Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C Connecting between two codes in C

yesmoli12

New Coder
hello i hope for some help with my code.
i need to write code that recive 10 string from the user and sort them in alphabetical order and if the string that the user enter is lower the 10 letters i need to complete the word he enter with **** for exmaple:
“enter string”
abcd , aaaaaa.
printf:
aaaaaa***
abcd*****
explanation:
i sort the strings in alphabetical order
in the first string it was only 6 Letters so i add 3 ***
in the second string it was only 4 Letters so i add 5**
i was able to write the code but i do it in two different codes and i dont know how to connect them
first : the code that sort in alphabetical order

C:
#include <string.h>
#include <stdio.h>

int main(){

    int i,j;
    char word[10][10],s[10];
    printf("Enter string:\n");
    for(i=0;i<10;i++)
    {
        scanf("%s",word[i]);
    }
    for(i=0;i<10;i++)
    {
        for(j=i+1;j<10;j++)
        {
            if(strcmp(word[i],word[j])==1)
            {
                strcpy(s,word[i]);
                strcpy(word[i],word[j]);
                strcpy(word[j],s);
            }
        }
    }
    i = 0;
    while (i<10)
    {
        printf("%s \n",word[i]);
        i++;
    }
    return 0;
}


the second code that add *** if there is less than 9 word
C:
#include <stdio.h>

int main()
{
    int i = 0;
    printf("enter string \n");
    char word[10] = {};
    scanf("%s", word);
    while (i < 9)
    {
        if (word[i] == '\0')
            word[i] = '!';
        i++;
    }
    printf("%s", word);
    return 0;
}

I really hope that someone here can help me to connect this two codes
 
hey

C:
#include <stdio.h>
#include <string.h>

int main()
{
    int n = 3;
    int m = 11;
    char str[n][m];
    char temp[m];

    for (int x = 0; x < n; x++)
    scanf("%s", str[x]);

    for (int x = 0; x < n; x++) {
    for (int y = 1 + x; y < n; y++) {
        if (strcmp(str[y + 1], str[y]) == 1) {
                strncpy(temp,str[y], m);
                strncpy(str[y],str[y+1], m);
                strncpy(str[y+1],temp, m);
        }
    }
    }

    puts("");

    // stars

    for (int x = 0; x < n; x++) {
        printf("%s", str[x]);
        if (strlen(str[x]) < 10)
            for (size_t y = 0; y  < 10 - strlen(str[x]); y++)
                printf("*");

        puts("");
    }

    return 0;
}

should work

: test1:

hallouf ich aaaaaaaaa

hallouf***
ich*******
aaaaaaaaa*
 

New Threads

Buy us a coffee!

Back
Top Bottom