-3

can please someone help me finding the error in my code. their are no syntax error. but somewhere it is wrong since i am not getting my desired output. the functions gets() and toupper() are not getting implemented from the library.

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

    int toupper(char d);
    char gets(char a[100]);

    int main(void)
    {
        int i;
        char a[100];
        printf("enter your name \n");
        gets(a);
        printf("%c",toupper(a[0]));
        for(i=1;a[i]!='\0';i++)
        {
            if(a[i]==' ')
            {
                printf("%c",toupper(a[i+1]));
            }

        }
        printf("\n");
        return 0;
    }



    int toupper(char d)
    {
        return (d-32);
    }

    char gets(char a[100])
    {
        int i;
        for(i=0;a[i] != '\0'+1;i++)
         {
            scanf("%c",&a[i]);
         }
          return a[i];
    }

1 Answers1

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

int
main(int argc, char *argv[])
{
    char s[512];

    printf("Enter your name: ");
    fflush(stdout);

    if (fgets(s, sizeof(s), stdin)) {

        int scanning_for_first = 1;

        for (size_t i = 0; i < sizeof(s) && s[i] != '\n' && s[i] != '\0'; i++)
        {
            if (scanning_for_first) {
                if (!isalnum(s[i])) continue;
                printf("%c.", toupper(s[i]));
                scanning_for_first = 0;
            }

            if (!isalnum(s[i])) {
                scanning_for_first = 1;
            }
        }
    }
    printf("\n");

    return 0;
}

Enter your name: John Fitzgerald Kennedy
J.F.K.
user3125367
  • 2,920
  • 1
  • 17
  • 17