Tom
Tom

Reputation: 1

Code in Code::blocks not working in visual studio 2013

Here is my code:

// SysProAss1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <ctype.h>


int _tmain(int argc, _TCHAR* argv[])
{
    {

    char line[20];

    //Asking the User to input some characters to use in the program
    printf("Enter a few characters please:\n");
    scanf_s("%s", line);

    //For loop to print each character of the string on a new line
    for (int i = 0; line[i]; ++i)
        {
        // If statement to check whether the character is an upper case vowel
        if (line[i] == 'A' || line[i] == 'E' || line[i] == 'I' || line[i] == 'O' || line[i] == 'U')
            printf("%c is an upper case vowel.\n", line[i]);

            // If statement to check whether the character is a lower case vowel
        else if (line[i] == 'a' || line[i] == 'e' || line[i] == 'i' || line[i] == 'o' || line[i] == 'u')
            printf("%c is a lower case vowel.\n", line[i]);

            // ispunct() function used to check whether the input character is a punctuation
            else if (ispunct(line[i]))
                printf("%c is a punctuation character. \n", line[i]);

                // Else statement to print the character if it does not fit the above if statements
                else 
                printf("%c\n", line[i]);

    }

}

}

The code will compile but when I input characters nothing is printed. I have tested to see if the string contains anything after entering some characters and it doesn't. Any help would be appriciated

Upvotes: 0

Views: 57

Answers (1)

Ajay Kolambekar
Ajay Kolambekar

Reputation: 11

Change scanf_s statement in your code to, scanf_s("%s", line, sizeof(line));

Upvotes: 1

Related Questions