system("cls") 사용 시 프로그램 죽는 문제...
튼싹
질문 제목 : 질문 내용 :
아래는 전광판 효과처럼 우에서 좌로 글씨가 흐르게 만들어보려는 건데요.
system(cls)를 넣으면 죽어버리네요...
이걸 빼면 죽지않는데 말이죠...
혹시 무엇때문인지 아시는 분 계신가요ㅜㅜ?#include windows.h
#include conio.h
#include stdio.h
#include stdlib.h
#include string.h#define true 1
#define false 0void gotoxy(int x, int y)
{
coord cur;
cur.x=x;
cur.y=y;
setconsolecursorposition(getstdhandle(std_output_handle),cur);
}void rotate(char *pstr, int repeat, int bflicker)
{
int i;
int j;
int strlen;
char *ptemp; strlen = strlen(pstr); ptemp = (char*)malloc(sizeof(char)*strlen+1); for(j=0; jrepeat; j++)
{
memset(ptemp,0,sizeof(char)*strlen);
for(i=0; i strlen; i++)
{
if(i==strlen-1)
ptemp[i] = pstr[0];
else
ptemp[i]=pstr[i+1];
}
strcpy(pstr,ptemp);
pstr[strlen] = null; printf(%s,pstr);
sleep(100);
//system(cls);
}
}void main()
{
int rotatenum = 10;
int stringlen;
char str[40] = hello world!!!;
char *pstr; stringlen = strlen(str);
pstr = (char*)malloc(sizeof(char)*stringlen+1);
strcpy(pstr, str);
//gotoxy(30,12);
rotate(pstr, rotatenum, false);
}
-
밤
자체 답변 달겠습니다.
결국 막 코딩하다가 발생한 이슈들 같습니다.
아래 내용 수정하면 잘 되네요~
도움 주신 분들 감사합니다 ^^
1.malloc 시 널문자 고려해서 할당.
pStr = (char*)malloc(sizeof(char)*(stringLen+1));
pTemp = (char*)malloc(sizeof(char)*(strLen+1));
2.strcpy에서 null채워지지 않은 상태에서 하면 문제되는듯.
for(i=0; i strL -
Schokolade
제가 했을때는 안죽는데... ^^;;;;
그 부분에서 죽는거 맞는지... F5로 실행해 보세요.
개발 툴은 뭘 사용하시는지?
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692230 | 하노이탑 질문입니다. (1) | 미쁘다 | 2025-04-21 |
2692210 | 정보 올림피아드 문제인데.. 풀이 과정이 궁금합니다.(재귀함수) (5) | 물티슈 | 2025-04-20 |
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |