사용자 입력을 받아서 출력으로 Morsecode로 바꾸는 프로그램을 작성 중입니다. 내 프로그램에 몇 가지 오류가 나타납니다. 내가해야 할 일이 확실치 않거나 여기에서 시도하십시오. 나는 알파에서 모스 코드까지 변환을 수행했다. 글자를 쓰고 싶지 않았기 때문에 글자를 바이너리 입력으로 바꾸었다.C 프로그래밍을 사용하여 구문을 가져 와서 morsecode로 변경
구문을 검사하고 문자열을 저장하려고했습니다. 그런 다음 for 루프를 사용하여 문자열 [i]를 1 씩 증가시켜 문자열의 각 주소를 확인합니다. 루프가 실행될 때마다 문자열 값을 INT A에 저장 한 다음 일치 항목에 대해 if = else-if 문을 체크인하여 반환하고 값을 인쇄합니다.
# include <stdio.h>
void checkphrase (char string[], int *px)
{
int i;
printf(" PHRASE ENTERED IS\n %s\n" , string[i]);
/* Prints the Phrase entered */
/* Start for loop to compare letters to the morse code equivalent */
for(i=0; i <= 30; i++)
{
px = string[i]; // pointer points the string value
a = px; // int a is assgined the value of px to be compared to morsecode
findmorse() // calls function to compare morsecode
}
return 0; // returns to main
}
void findmorse (int a)
/* originoally had a = the aphpabet but converted to binary */
{
if (a == 01000001)
Printf(" • — \n");
else if (a == 01000010)
Printf(" — • • • \n");
else if (a == 01000011)
Printf(" — • — • \n");
else if (a == 01000100)
Printf(" — • • \n");
else if (a == 01000101)
Printf(" • \n");
else if (a == 01000110)
Printf(" • • — • \n");
else if (a == 01000111)
Printf(" — — • \n");
else if (a == 01001000)
Printf(" • • • • \n");
else if (a == 01001001)
Printf(" • • \n");
else if (a == 01001010)
Printf(" • — — — \n");
else if (a == 01001011)
Printf(" — • — \n");
else if (a == 01001100)
Printf(" • — • • \n");
else if (a == 01001101)
Printf(" — — \n");
else if (a == 01001110)
Printf(" — • \n");
else if (a == 01001111)
Printf(" — — — \n");
else if (a == 01010000)
Printf(" • — — • \n");
else if (a == 01010001)
Printf(" — — • — \n");
else if (a == 01010010)
Printf(" • — • \n");
else if (a == 01010011)
Printf(" • • • \n");
else if (a == 01010100)
Printf(" — \n");
else if (a == 01010101)
Printf(" • • — \n");
else if (a == 01010110)
Printf(" • • • — \n");
else if (a == 01010111)
Printf(" • -- \n");
else if (a == 01011000)
Printf(" -• • - \n");
else if (a == 01011001)
Printf(" -• -- \n");
else if (a == 01011010)
Printf(" --• • \n");
/* Numbers */
else if (a == 1)
Printf(" · – – – – \n");
else if (a == 2)
Printf(" · · – – – \n");
else if (a == 3)
Printf(" · · · – – \n");
else if (a == 4)
Printf(" · · · · – \n");
else if (a == 5)
Printf(" · · · · · \n");
else if (a == 6)
Printf(" – · · · · \n");
else if (a == 7)
Printf(" – – · · · \n");
else if (a == 8)
Printf(" – – – · · \n");
else if (a == 9)
Printf(" – – – – · \n");
else if (a == 0)
Printf(" – – – – – \n");
/* return to check phrase */
return string[};
}
int main() // main function
{
printf("PLEASE ENTER A PHRASE UNDER 30 CHARACTERS\n");
scanf(" %s " , string[]);
checkphrase() // takes string to the checkphrase function
return 0;
}
무엇이 당신의 질문입니까? –
첫 번째 문제 01001100은 십진수 1,001,100을 의미합니다. 나는 당신이 이진 문학을 원한다고 생각한다. 그것은 직설적이지 않다. http://stackoverflow.com/questions/2611764/can-i-use-a-binary-literal-in-c-or-c – gbtimmon
기능을해야한다고 생각했기 때문에 내가 설정 한 방식에 문제가 있습니까? 또는 함수에 대한 나의 주장과 함께? – Pwoods