-6

What are the mistakes i did in the code ? It is not giving any output. The question is given in the image. I am using the ASCII variable set to print the set of alphabet and digits .

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

int main()
{
    int i, j, temp, t, s, e;
    char test[20], start = 'a', end = 'z';
    scanf("%s", test);
    for (i = 0; i < strlen(test) && (test[i] == '-'); i++);
    for (; i < strlen(test););
    {
        if (isalpha(test[i]) != 0)
        {
            start = test[i];
            for (; (i < strlen(test)) && (isdigit(test[i]) == 0); i++);
        }

        end = test[i - 1];
        temp = end - start + 1;

        if (isdigit(test[i]) != 0)
        {
            s = test[i];
            for (; (i < strlen(test)) && (isalpha(test[i]) == 0); i++);
        }

        e = test[i - 1];
        t = e - s + 1;

        for (j = 0; j < temp; ++j, start++)
        {
            printf("%c", start);
        }
        printf("\n");

        for (j = 0; j < t; ++j, s++)
        {
            printf("%c", s);
        }
        printf("\n");
    }

    return 0;
}
Swordfish
  • 12,971
  • 3
  • 21
  • 43
theviralv
  • 7
  • 3
  • Text should be posted as text and not as a liked image. (That is missing words on the right side.) – Swordfish Oct 22 '18 at 03:53
  • 3
    You are ending the for loop with a semicolon. The rest of the bracket is not inside the loop `for (; i < strlen(test););` Also, do you want 2 for loops here? – Rishikesh Raje Oct 22 '18 at 04:33

1 Answers1

1

You have put a ; at the end of for loops and that's the reason the body of the for loop is not being executed as expected. Effect of semicolon after 'for' loop

for (i = 0; i < strlen(test) && (test[i] == '-'); i++);
for (; i < strlen(test););
for (; (i < strlen(test)) && (isdigit(test[i]) == 0); i++);
for (; (i < strlen(test)) && (isalpha(test[i]) == 0); i++);

Remove the ; from the end of each for loop.

You should also remove the inner for loop as it has already mentioned in the outer for loop. Please check the body of each for loop properly.

suvojit_007
  • 1,690
  • 2
  • 17
  • 23