none
Debug Assertion Failed!

    Question

  • file is as follow,

     #include "stdafx.h"
    #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <windows.h>
     
     using namespace std;

    void main()
    {
     SYSTEMTIME sys_time;       //将变量值设置为本地时间
        GetLocalTime( &sys_time );       //输出时间
     printf( "Date and Time : %4d/%02d/%02d %02d:%02d:%02d.%03d Week%1d\n",sys_time.wYear,
             sys_time.wMonth,
             sys_time.wDay, 
             sys_time.wHour, 
             sys_time.wMinute,
             sys_time.wSecond,
             sys_time.wMilliseconds,
             sys_time.wDayOfWeek);
    char c;
        FILE *fp;
        fp=fopen("f:\download\temptest.txt","r");
        printf("output file.txt: \n");
        while ((c=getc(fp))!=EOF)      ////<----it seems here matter
       putchar(c);
        printf("-----------------\n");
      
    //c=getc(fp);

        system("pause");

    }

    this is console plateform prog. under vc++2008 express.

    after build, when debug, I have got the dialog block as folllow,

    it seems while statement matter, what's wrong with that?

    Thursday, November 29, 2012 4:28 PM

Answers

  • The backslash is a special character in quoted strings. You need this in order to make a backslash in the quoted file name:

    fopen("f:\\download\\temptest.txt","r");

    • Marked as answer by zhgart Thursday, November 29, 2012 5:05 PM
    Thursday, November 29, 2012 4:33 PM

All replies

  • The backslash is a special character in quoted strings. You need this in order to make a backslash in the quoted file name:

    fopen("f:\\download\\temptest.txt","r");

    • Marked as answer by zhgart Thursday, November 29, 2012 5:05 PM
    Thursday, November 29, 2012 4:33 PM
  • Also, make sure you always check the return value from fopen.
    Thursday, November 29, 2012 4:36 PM
  • _ptr CXX0030: Error: expression cannot be evaluated 
    Thursday, November 29, 2012 4:42 PM
  • And it says: 

    Expression: (stream !=null)

    So, the error is related to stream operation which in your code is opening the file with fopen.

    Thursday, November 29, 2012 4:44 PM
  • no such expression.Expression: (stream !=null)

    it seems this statement is matter

     fp=fopen("f:\download\temptest.txt","r");
        what's wrong with it?


    • Edited by zhgart Thursday, November 29, 2012 5:02 PM
    Thursday, November 29, 2012 5:01 PM
  • The backslash is a special character in quoted strings. You need this in order to make a backslash in the quoted file name:

    fopen("f:\\download\\temptest.txt","r");

    quit rright!!!!!!

    well done.

    thank you all.

    Thursday, November 29, 2012 5:04 PM