<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'i cant understand the error' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'i cant understand the error' posted on the 'Beginner C/C++' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2008 Programmers Heaven</copyright>
    <pubDate>Tue, 13 May 2008 20:53:56 -0700</pubDate>
    <lastBuildDate>Tue, 13 May 2008 20:53:56 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>i cant understand the error</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/370650/370650/ReadMessage.aspx</link>
      <description>&lt;div class="BoardMessageAreaPrinterFriendly"&gt;
&lt;h2 class="BoardMessageSubjectPrinterFriendly"&gt;i cant understand the error&lt;/h2&gt;
&lt;div class="BoardMessageInfoPrinterFriendly"&gt;Posted by  on 27 Mar 2008 at 7:44 AM&lt;/div&gt;
&lt;div class="BoardMessageBodyPrinterFriendly"&gt;this is the code&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
        FILE *fpin, *fpout;&lt;br /&gt;
        int ch,position;&lt;br /&gt;
        unsigned line=1;&lt;br /&gt;
        char filename[100];&lt;br /&gt;
&lt;br /&gt;
        printf("Please enter the file name\n");&lt;br /&gt;
        scanf("%s",&amp;amp;filename);&lt;br /&gt;
&lt;br /&gt;
        if((fpin=fopen(filename,"r")) == NULL)&lt;br /&gt;
        {&lt;br /&gt;
                printf("Couldnt open file %s for input\n",filename);&lt;br /&gt;
                exit(1);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        if((fpout=fopen("res.txt","w")) == NULL)&lt;br /&gt;
        {&lt;br /&gt;
                printf("Couldnt open \"res.txt\" for output\n");&lt;br /&gt;
                exit(1);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        fprintf(fpout,"%d ",line);&lt;br /&gt;
        while ((ch=getc(fpin)) != EOF)&lt;br /&gt;
                if( ch == '\n')&lt;br /&gt;
                        {&lt;br /&gt;
                                putc(ch,fpout);&lt;br /&gt;
                                fprintf(fpout,"%d ",++line);&lt;br /&gt;
                        }&lt;br /&gt;
                else&lt;br /&gt;
                        putc(ch,fpout);&lt;br /&gt;
&lt;br /&gt;
        fclose(fpin);&lt;br /&gt;
        fclose(fpout);&lt;br /&gt;
&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$ more input.txt&lt;br /&gt;
this is the first line&lt;br /&gt;
this is the second line&lt;br /&gt;
this is the third line&lt;br /&gt;
&lt;br /&gt;
$ more res.txt&lt;br /&gt;
1 this is the first line&lt;br /&gt;
2 this is the second line&lt;br /&gt;
3 this is the third line&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It seems that something happens and it cant read the EOF char.&lt;br /&gt;
OR even it reads it does something wrong. &lt;br /&gt;
I cant understand why.&lt;br /&gt;
&lt;br /&gt;
I ve double-checked the input file if it has another new line char but it doesnt have one. I ve checked it with vi as well and there is no other char after the last char.&lt;br /&gt;
&lt;br /&gt;
Could you please help me on this strange issue ?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</description>
      <pubDate>Thu, 27 Mar 2008 07:44:59 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
    <item>
      <title>Re: i cant understand the error</title>
      <link>http://www.programmersheaven.com/mb/beginnercpp/370650/370661/ReadMessage.aspx#370661</link>
      <description>&lt;div class="BoardMessageAreaPrinterFriendly"&gt;
&lt;h2 class="BoardMessageSubjectPrinterFriendly"&gt;Re: i cant understand the error&lt;/h2&gt;
&lt;div class="BoardMessageInfoPrinterFriendly"&gt;Posted by  on 27 Mar 2008 at 4:57 PM&lt;/div&gt;
&lt;div class="BoardMessageBodyPrinterFriendly"&gt;Hi,&lt;br /&gt;
&lt;br /&gt;
Are you completely sure the last 0x0A char isn't there ?&lt;br /&gt;
&lt;br /&gt;
Editors like vi, vim, gedit, usually appends a new line \n even when you don't see it (I meant .. you can't see a new line, but you can't get into the next one also, but ... it's there!). Try to use &lt;em&gt;:%!xxd&lt;/em&gt; inside vim on your input.txt (to filter with xxd and get the hexadecimal view, you can't edit from there, it's only a view). (A note, Microsoft Notepad doesn't add anything.)&lt;br /&gt;
&lt;br /&gt;
Or use &lt;em&gt;biew&lt;/em&gt; (F2 - Hex) or midnight commander &lt;em&gt;mc&lt;/em&gt; (F3View - F4Hex) to observe that effectively the 0x0A char is there.&lt;br /&gt;
&lt;br /&gt;
Even easier ... try :&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;cat input.txt&lt;br /&gt;
if you get this :&lt;/strong&gt;&lt;br /&gt;
&lt;em&gt;this is the last line&lt;br /&gt;
username@SERVER:~$&lt;/em&gt;&lt;br /&gt;
&lt;strong&gt;you have the \n but&lt;br /&gt;
if you get this :&lt;/strong&gt;&lt;br /&gt;
&lt;em&gt;this is the last lineusername@SERVER:~$&lt;/em&gt;&lt;br /&gt;
&lt;strong&gt;the \n isn't there.&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Regards,&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: Red;"&gt;Good luck!&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: Blue;"&gt;Hackman&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description>
      <pubDate>Thu, 27 Mar 2008 16:57:59 -0700</pubDate>
      <category>Beginner C/C++</category>
    </item>
  </channel>
</rss>