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);
}
-
agine
자체 답변 달겠습니다.
결국 막 코딩하다가 발생한 이슈들 같습니다.
아래 내용 수정하면 잘 되네요~
도움 주신 분들 감사합니다 ^^
1.malloc 시 널문자 고려해서 할당.
pStr = (char*)malloc(sizeof(char)*(stringLen+1));
pTemp = (char*)malloc(sizeof(char)*(strLen+1));
2.strcpy에서 null채워지지 않은 상태에서 하면 문제되는듯.
for(i=0; i strL -
겨슬
제가 했을때는 안죽는데... ^^;;;;
그 부분에서 죽는거 맞는지... F5로 실행해 보세요.
개발 툴은 뭘 사용하시는지?
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2699304 | [기초]아직 안주무시는분 계신가요..?포인터배열? 좀 도와주세요. | 놀리기 | 2025-06-24 |
2699272 | printf() 함수이용해서 프로그램 만들기 질문요! (5) | 다가 | 2025-06-24 |
2699221 | PUSH와 POP코드를 더 간단하게 어떻게 해야할까요? | 파라미 | 2025-06-24 |
2699192 | 설치오류가 자꾸 나요 한번봐주세여~ (1) | 소녀틳향기 | 2025-06-23 |
2699161 | for loop안에 있는 if문 (9) | Orange | 2025-06-23 |
2699105 | 링크더리스트 이전 링크값 출력함수. | 꼬꼬마 | 2025-06-23 |
2699078 | 정수를 한자리씩 배열에 담는 법은 어떻게 하나요.. (4) | 귀염포텐 | 2025-06-22 |
2699024 | C언어 공부하려는데 도와주세요!!! (2) | 달님 | 2025-06-22 |
2698994 | 날짜 계산하는 C 코드 짜고 있는데 꽉 막혀서 질문드립니다.. (6) | 별 | 2025-06-22 |
2698967 | 파일삭제 윈도우 폴더까지 접근하게하는 함수가 뭔가요 (2) | 샤인 | 2025-06-21 |
2698938 | c언어 메모리질문 (3) | 나래 | 2025-06-21 |
2698909 | 서비스 요청 고객 관리 프로그램 짜는것좀 도와주세요ㅜㅜ (4) | 궁수자리 | 2025-06-21 |
2698882 | 프로그래밍좀 짜주세요 (3) | 황예 | 2025-06-21 |
2698855 | 카프-라빈 알고리즘 코딩 분석좀 도와주세요.. | 꽃봄 | 2025-06-20 |
2698829 | 학점계산기 (7) | MyWay | 2025-06-20 |
2698782 | 기초적인 함수 질문이요ㅠㅠㅠㅠ | 내담 | 2025-06-20 |
2698749 | 프로그램 짜던 도중 패닉입니다...ㅜ | 파랑 | 2025-06-19 |
2698719 | 조건부컴파일 질문입니다.~ (2) | 큐트 | 2025-06-19 |
2698693 | 재귀 함수 에러 | 바닐라 | 2025-06-19 |
2698673 | 고민이있는데 들어좀주세요!! (1) | 초코맛캔디 | 2025-06-19 |