谢绝用MFC等非API代码:
小弟在C++下做了一个求单纯形法的的软件,现在想做成可视化界面的,VC正在学API编程,那本<windows程序设计>太厚没看多少,在这里想请教各位高手.
当我选择打开,打开一个txt文件,里面有这样的内容
1a+2b+3c+4d+5e=10
2a+4b-c+d+e=7
9a-6b+3c+d+e=1
怎么样把它们的系数1 2 3 4 5 10
                  2 4 -1 1 1 7
                  9 -6 3 1 1 1
存入如上的一个5*3的数组里面呀
最好给出完整的原码,这样我才好理解,闲分少我可以再给!

解决方案 »

  1.   

    我不懂MFC想SDK学完了再学那个,怕你们用MFC写的我不懂!
      

  2.   

    用得着MFC吗?
    TURBOC 就可以了。
      

  3.   

    #include <windows.h>
    #include <stdio.h>
    #include <string.h>#define WORDDEF  0
    #define NUMDEF   1
    #define FLAGDEF  2
    #define BLANKDEF 3
    #define ERRORDEF 4long WINAPI WndProc(HWND,UINT,UINT,long); 
    BOOL InitWindowsClass(HINSTANCE);
    BOOL InitWindows(HINSTANCE,int);
    BOOL PushIntoArray();
    char buffer[1024];
    int Array[3][6];
    void ConnectBuffer(char temp);
    int GetTypeAndInfo(char temp);
    HWND hWndMain;int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
    {
    MSG Msg;
    if(!InitWindowsClass(hInstance))
    return FALSE;
    if(!InitWindows(hInstance,nCmdShow))
    return FALSE;
    PushIntoArray();
    while(GetMessage(&Msg,0,0,0))
    {
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
    }
    return Msg.wParam;
    }long WINAPI WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    HDC hdc;
    PAINTSTRUCT ps;
    int m,n;
    // TEXTMETRIC tm;
    char lpsz[]="Hello World !";    switch(message) 
        {
    case WM_PAINT:
    hdc=BeginPaint(hwnd,&ps);
    char temp[1024],_temp[1024];
    *temp='\0';
    for(m=0;m<3;m++)
    {
    for(n=0;n<6;n++)
    {
    if ( n != 5)
    sprintf(_temp," %d ",Array[m][n]);
    else
    sprintf(_temp," %d\n",Array[m][n]);
    strcat(temp,_temp);

    } TextOut(hdc,100,100,temp,(int)strlen(temp));
    EndPaint(hwnd,&ps);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    return 0;
    default:
    return DefWindowProc(hwnd,message,wParam,lParam);
    }
     return(0);
    }BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
    {
    HWND hwnd;
    hwnd=CreateWindow("Test","Binaryword's Test",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,800,600,NULL,NULL,hInstance,NULL);
    if(!hwnd)
    return FALSE;
    hWndMain=hwnd;
    ShowWindow(hwnd,nCmdShow);
    UpdateWindow(hwnd); 
    return TRUE;
    }BOOL InitWindowsClass(HINSTANCE hInstance)
    {
    WNDCLASS wndclass;
    wndclass.style=0;
    wndclass.lpfnWndProc=WndProc;
    wndclass.cbClsExtra=0;
    wndclass.cbWndExtra=0;
    wndclass.hInstance=hInstance;
    wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
    wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName=NULL;
    wndclass.lpszClassName="Test";
    return RegisterClass(&wndclass);
    }BOOL PushIntoArray()
    {
    FILE *file;
    if((file=fopen("D:\\test.txt","rb"))==NULL)
    {
    MessageBox(NULL,"Error:Fail to open the file","Error",0);
    return FALSE;
    }
    int count=0;
    char buf;
    *buffer='\0';
    buf=getc(file);
    while(buf!=EOF)
    {

    int m=GetTypeAndInfo(buf);
    if (m == BLANKDEF || m == FLAGDEF || m == WORDDEF)
    {
    if(strlen(buffer)>0)
    {
    Array[count/6][count%6]=*buffer;

    count++;
    }
    *buffer='\0';
    buf=getc(file);
    } else if ( m == NUMDEF )
    {
    ConnectBuffer(buf);
    MessageBox(NULL,&buf,"Error",0);
    buf=getc(file);
    } else 
    {
    buf=getc(file);
    }
    }
    return TRUE;
    }void ConnectBuffer(char temp)
    {
    char string[2];
    *string=temp;
    *(string+1)='\0';
    strcat(buffer,string);
    MessageBox(NULL,string,"Error",0);
    }int GetTypeAndInfo(char temp)
    {
    if(temp >= 'A' && temp <='Z' || temp >='a' && temp <= 'z')
    return WORDDEF;
    else if(temp >= '1' && temp<= '0')
    return NUMDEF;
    else if(temp == ' ' || temp == 9 || temp ==10) 
    return BLANKDEF else if(temp == '+' || temp == '-' || temp == '=' || temp == '*' || temp =='/')
    return FLAGDEF;
    else
    return ERRORDEF;
    }
    在判断符号类型的时候有点障碍,你把正确的asc码写进去就行了,这是按照 词法分析器写的,不过识别能里有限,如果你采用一些双字符的符号就会出错,需要另外设置
      

  4.   

    里面有很多MSGBOX是我调试的时候用的,写的仓促,没有书本参考,可能会有错误。