0

I'm trying to build a program where the user picks a consonant/vowel and a random letter is chosen and added to a string each time, similar to the TV show countdown. I'm hit with the error in the title. When I try to compile the console reads that the file is not readable as an executable.

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

#include "stdafx.h"
#include <stdlib.h>
#include <string>
using namespace std;

int main(){

char type, letters[10];
char vowels[6] = { 'A', 'E', 'I', 'O', 'U' };
char consonants[22] = { "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z" };
int i, j, k, l;

for (i = 0; i < 9; i++){
printf("Vowel or consonant? (V/C)");
scanf("%c", &type);

if (type == 'V')
    for (k = 0; k<1; k++){
        j = (rand() % 5);
        strcat(letters, vowels[j]);

    }
if (type == 'C')
    for (l = 0; l<1; l++){
        j = (rand() % 21);
        strcat(letters, consonants[j]);

    }
else
    printf("Invalid!");
break;
}
    printf("%s", letters);
return 0;
}
alk
  • 69,737
  • 10
  • 105
  • 255
  • This might not be related to the problem, but the initialization of `consonants` using string literals looks weird. – MikeCAT Mar 26 '16 at 06:29
  • Passing `vowels[j]` or other object of `char` as arguments of `strcat` and using value of uninitialized variable haing automatic storage duraton `letteers` is bad. – MikeCAT Mar 26 '16 at 06:30
  • 1
    Does http://stackoverflow.com/q/126751/62576 help? – Ken White Mar 26 '16 at 06:33
  • 2
    In your `Debug` folder there's a file ending in `.pdb`, this is the program database, and it contains debug information for your program. If it can't be overwritten it means it's in use already, perhaps by another instance of Visual Studio running an active debug session, or simply by your program running already (though that would result in a failure to create the executable file first). If you can't remove the file manually, and no other instance of Visual Studio is running, and you rpgram isn't running (check the task manager) then you might have to restart your computer. – Some programmer dude Mar 26 '16 at 06:34
  • 1
    This is an environmental problem, chronically caused by crappy anti-malware. You must make an exclusion for your build folder(s). If it is Avast then uninstall asap. – Hans Passant Mar 26 '16 at 06:48
  • This makes sense, it's a friend's computer I borrowed. @MikeCAT could you elaborate on your second comment, I'm afraid I don't follow. – Eamon Cullen Mar 26 '16 at 07:13
  • @EamonCullen Avast is notorious for stopping you doing things that you need/want to do. It does not like people developing software and tries to stop them doing it. – Martin James Mar 26 '16 at 07:55

0 Answers0