compiler error

This is a discussion on compiler error within the C++ Programming forums, part of the General Programming Boards category; Hi I wrote fllowing for reading file line by line till I get end of file . I could not ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    3

    compiler error

    Hi
    I wrote fllowing for reading file line by line till I get end of file . I could not run it properly. I compile in VC++ but basic syntax is C only. PLease help me out !!!!!!

    Is this correct way to read file till end --------
    while(fgets(string1,sizeof(string1),text) != "/0")

    Code:
    // ACIDlg.cpp : implementation file
    //
    
    #include "stdafx.h"
    #include "ACI.h"
    #include "ACIDlg.h"
    #include "stdio.h"
    #include "math.h"
    #include "stdlib.h"
    #include "stdio.h"
    #include "iostream.h"
    #include "string.h"
    
    FILE *text;
    char string1[BUFSIZ];
    char *string2;
    char stri[10];
    
    
    void CACIDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CACIDlg)
    	DDX_Control(pDX, IDC_LIST1, m_strrr);
    //	DDX_Text(pDX, IDC_EDIT1, m_st);
    	//}}AFX_DATA_MAP
    while(fgets(string1,sizeof(string1),text) != "/0")
    {
    //fgets(pstring1,sizeof(pstring1),text);
     if ((string2 = strchr(string1, '\n')) != NULL)
          *string2 = '\0';
    m_st=string1;
    m_strrr.AddString(m_st);
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    > I compile in VC++ but basic syntax is C only
    But it's written in C++ - only C++ has all that class::member stuff

    > #include "stdio.h"
    Standard headers use <> not "" for inclusion

    > while(fgets(string1,sizeof(string1),text) != "/0")
    Because its
    while(fgets(string1,sizeof(string1),text) != NULL )

    Next time
    1. Use code tags
    2. Use the correct forum for your code
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21