C++ Morse Code

Hello everyone! I'm having trouble trying to find out what's wrong with my code and i would really appreciate if someone could help me, please.

when running the code i get this message:

ld.exe||cannot open output file bin\Debug\MorseCode.exe Permission denied|
||error: ld returned 1 exit status|


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  
#include <iostream>
#include <string>
#include <Windows.h>

using namespace std;

string A=".-   ",B="-... ",C="-.-. ",D="-..  ",E=".    ",F="..-. ",G="--.  ",H=".... ",I="..   ",J=".--- ",K="-.-  ",L=".-.. ",M="--   ",N="-.   ",O="---  ",P=".--. ",Q="--.- ",R=".-.  ",S="...  ",T="-    ",U="..-  ",V="...- ",W=".--  ",X="-..- ",Y="-.-- ",Z="--.. ",one=".----",two="..---",three="...--",four="....-",five=".....",six="-....",seven="--...",eight="---..",nine="----.",zero="-----";

void morseCode(string text, int n);

void toUpper(string &text);

void check(string word, int n);

int main()
{
    string text;
    getline(cin, text);
    toUpper(text);
    morseCode(text, 5);

    return 0;
}

void toUpper(string &text){

    for(int i=0;i<text.length();i++){

        text[i] = toupper(text[i]);
    }
}

void morseCode(string text, int n){

    char help;
    string helpText = text;
    cout << "|";

    for(int i=0;i<helpText.length();i++){

        help = text.at(0);
        switch(help){
            case 'A':check(A,n);break;
            case 'B':check(B,n);break;
            case 'C':check(C,n);break;
            case 'D':check(D,n);break;
            case 'E':check(E,n);break;
            case 'F':check(F,n);break;
            case 'G':check(G,n);break;
            case 'H':check(H,n);break;
            case 'I':check(I,n);break;
            case 'J':check(J,n);break;
            case 'K':check(K,n);break;
            case 'L':check(L,n);break;
            case 'M':check(M,n);break;
            case 'N':check(N,n);break;
            case 'O':check(O,n);break;
            case 'P':check(P,n);break;
            case 'Q':check(Q,n);break;
            case 'R':check(R,n);break;
            case 'S':check(S,n);break;
            case 'T':check(T,n);break;
            case 'U':check(U,n);break;
            case 'V':check(V,n);break;
            case 'W':check(W,n);break;
            case 'Y':check(Y,n);break;
            case 'X':check(X,n);break;
            case 'Z':check(Z,n);break;
            case '1':check(one,n);break;
            case '2':check(two,n);break;
            case '3':check(three,n);break;
            case '4':check(four,n);break;
            case '5':check(five,n);break;
            case '6':check(six,n);break;
            case '7':check(seven,n);break;
            case '8':check(eight,n);break;
            case '9':check(nine,n);break;
            case '0':check(zero,n);break;
            default : cout << "\t\t|";

        }

        text.erase(0,1);

    }

}

void check(string word, int n){

    for(int i=0;i<n;i++){
        if(word.at(i)=='.'){

            cout << ".";
            Sleep(0);
        }else if(word.at(i)=='-'){

            cout << "-";
            Sleep(0);

        }else{

         break;

        }

    }

    cout << "|";
}

Last edited on
What makes you think that there is something wrong with the code?

oh yeah, my bad forgot to say, when running the code i get this message:

ld.exe||cannot open output file bin\Debug\MorseCode.exe Permission denied|
||error: ld returned 1 exit status|

Either is something wrong with the code or compiler...
Either is something wrong with the code or compiler...

Probably nothing wrong with either. It appears that you don't have permission to write to "bin\Debug\MorseCode.exe". This may be because there is still an instance of that program running, or perhaps your Anti-Virus program has flagged that file as suspicious and won't allow you to write the file, or you are attempting to write that file to a directory that you don't have the proper permissions.

turned off my anti-virus, ran the code, still not working, if you know, can you please tell me what i should do to get rid of this problem ?
Hello MongKong,

What IDE are you using?

Andy
I don't do Windows so I'm only guessing.

Did you try closing your IDE and restarting it?

If that doesn't solve the problem, have you tried restarting Windows?

Where exactly are you trying to write the executable (complete path?)?

a common cause of this issue is that you were debugging the program and ran it, and it is still running an old copy in the background, possibly totally hidden to everything but the task manager. If the program is running, the operating system will NOT let you delete or edit the executable.

search the taskmanager for morscode.exe and kill it.
i use CodeBlocks

i tried restarting it

i haven't tried restarting windows

and by complete path, you mean this ? :
C:\MinGW

or my code is on usb, if thats what you mean
Thank you jonnin, that was it, killed it, ran the program and all worked fine.

And thank you jib and Handy Andy aswell !
Hello MongKong,

Sorry I am not familiar with CodeBlocks. On occasion with VS I have to clean the solution and the find the ".exe" file and manually delete it. Then recompile the files.

Or as jlb first said the directory or sub-directory on the flash drive may not have write permission. I would check the permissions on the flash drive.

Andy

and by complete path, you mean this ? :

I hope that's not the complete path, you should never write anything to that directory.

I mean where exactly are you trying to write the project information. The complete path, the path from the root directory. Such as:

C:\home\myProjects\morse\bin\Debug\MorseCode.exe
F:\myfiles\myProjects\morse\bin\Debug\MorseCode.exe

oh yeah my bad that was compiler's installation directory, here it is:

J:\MorseCode\bin\Debug\MorseCode.exe


I mean the thing is, i had another copy of this code on my local drive, and i ran that and still didnt work. So i think the permission are all there... Might be wrong, i dont know much about stuff like this..
Topic archived. No new replies allowed.