我刚学VC++一个月,有C语言基础。我照书编了一个显示当前时间的程序。可是有一个错误和一个警告。错误提示是“error C2017: illegal escape sequence”,出错那一行是93行,代码是“str[strlen(str)-1]= \0;”。警告提示是“warning C4013: 'RegisterClassEX' undefined; assuming extern returning int”。我查了MSDN,\0应该是表示ASII的0,或是说表示NUL,可是我把\0改为0,或是NUL时,编译可以通过,可是连接时出现了三个错误“time.obj : error LNK2001: unresolved external symbol _RegisterClassEX” “LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16”  “ebug/time.exe : fatal error LNK1120: 2 unresolved externals”。至于那个警告,我头文件包括了windows.h和winuser.h乐,为什么还是不行?
高手们给指点一下吧,我搞了很久了也没解决。libcd.lib我也连接了。源代码如下/* A clock program.*/#include<windows.h>
#include<string.h>
#include<stdio.h>
#include<time.h>LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);LPCTSTR szWinName = "WinClock"; /*name of window class*/
char str[255] = " "; /*holds output string*/int WINAPIWinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR IpszArgs,int nWinMode)
{ HWND hwnd;
  MSG msg;
  WNDCLASSEX wcl;
  
  /*Define a window class*/
  wcl.cbSize = sizeof(WNDCLASSEX);
  wcl.hInstance = hThisInst;
  wcl.lpszClassName = szWinName;
  wcl.lpfnWndProc = WindowFunc;
  wcl.style = 0;
  wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
  wcl.hIconSm = LoadIcon(NULL,IDI_WINLOGO);
  wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
  wcl.lpszMenuName = NULL;
  wcl.cbClsExtra = 0;
  wcl.cbWndExtra = 0;  /*Make the window white.*/
  wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);  /*Register the window class.*/
  if(!RegisterClassEx(&wcl)) return 0;  /*Now that a widow class has been registered,a window can be created.*/
  hwnd = CreateWindow(
      szWinName,
      "Clock",
      WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      CW_USEDEFAULT,
      HWND_DESKTOP,
      NULL,
      hThisInst,
      NULL);  /*Display the window.*/
  ShowWindow(hwnd,nWinMode);  /*start a timer -- interrupt once per second*/
  SetTimer(hwnd,1,1000,NULL);  UpdateWindow(hwnd);  /*Create the message loop.*/
  while(GetMessage(&msg,NULL,0,0))
  { TranslateMessage(&msg);
    DispatchMessage(&msg);
  }  KillTimer(hwnd,1);  return msg.wParam;
}/*This function is called by Windows 98 and is passed messages from the mdssafe queue.
*/
LRESULT CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{ HDC hdc;
  PAINTSTRUCT paintstruct;
  struct tm *newtime;
  time_t t;  switch(message)
  { case WM_PAINT:
     hdc = BeginPaint(hwnd,&paintstruct);
     TextOut(hdc,1,1,str,strlen(str));
     EndPaint(hwnd,&paintstruct);
     break;  case WM_TIMER:
      /*get the new time*/
      t = time(NULL);
      newtime = localtime(&t);      /*display the mew time*/
      strcpy(str,asctime(newtime));
      str[strlen(str)-1]= \0; 
      InvalidateRect(hwnd,NULL,0);
      break;  case WM_DESTROY:
      PostQuitMessage(0);
      break;
  default:
        /*Let Windows98 process any messages not specified in the preceding switch statement*/
        return DefWindowProc(hwnd,message,wParam,lParam);
  }
  return 0;
}

解决方案 »

  1.   

    给char赋值的时候少了‘’  str[strlen(str)-1]= '\0';;还有一个非编译的错误
    strlen是不包括‘\0’的长度的。strlen(str)-1就多扣了一个字符。
      

  2.   

    老大门,编译是通过了,可是在连接时会出错,提示"LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16"
    "Debug/time.exe : fatal error LNK1120: 1 unresolved externals"
    是啥意思?咋解决?
      

  3.   

    我也是一个初学者,以下意见仅供参考,
    --->你的程序可能是一个WINAPI程序,
    --->你的程序又包含一些纯  c 的头文件
      

  4.   

    int WINAPI WinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR IpszArgs,int nWinMode) WinMain和WINAPI应该分开,如果是分开的,你还要把文件名改为.c,
    LNK2001: unresolved external symbol _WinMain@16"
    "Debug/time.exe : fatal error LNK1120: 1 unresolved externals"
    是说有不能定位的符号_WinMain@16,其实是找不到程序的入口点。
      

  5.   

    两个问题
    1、str[strlen(str)-1]= '\0'; 即\0加引号''
    2、int WINAPIWinMain中加空格int WINAPI WinMain