#include <stdio.h>
#include <windows.h>
#include <time.h>
#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
void main()
{
char * macbuf[10] = {"", "", "", "", "", "", "", "", "", ""};
char * mac;
mac = "12:13:14:15:16:17";
ifstream fin;
fin.open("mac.txt");
if (fin.fail()){
cout << "파일 오픈에 실패했습니다." << endl;
}
fin >> macbuf[0] >> macbuf[1] >> macbuf[2] >> macbuf[3];
fin.close();
printf("%s\n", mac);
printf("%s\n", macbuf[0]);
printf("%s\n", macbuf[1]);
printf("%s\n", macbuf[2]);
printf("%s\n", macbuf[3]);
printf("%s\n", macbuf[4]);
printf("%s\n", macbuf[5]);
printf("%s\n", macbuf[6]);
}
여기서 fin >> macbuf[0] >> macbuf[1] >> macbuf[2] >> macbuf[3]; 부분에 오류가 있는거같은데
뭐가 문제인지 모르겠습니다 계속 프로그램 실행이 정지되었습니다라 뜹니다..
응 그래서 mac.txt 내용이 뭔데?
char* c = "";
char* c = ""; strcpy(c, "asdfasdf", strlen("asdfasdf")); 이라고 한 거나 똑같은 상황. 즉, 없는 공간(정확히는 이미 정해진 공간)에 뭔가를 쓰려고 하니까 죽는거임.
char * macbuf[10] = {"", "", "", "", "", "", "", "", "", ""}; => std::string macbuf[10]; 으로 바꿔보셈. 잘 모르겠으면 std string c++ 이라는 keyword로 구글링 고고