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로 실행해 보세요.
개발 툴은 뭘 사용하시는지?