#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main()
{
FILE *fp;
char ch;
if((fp=fopen("123.txt","r"))==NULL)
printf("file cannot open \n");
else
printf("file opened for writing \n");
while ( ( ch = fgetc(fp) ) != EOF ) //  Be careful , Use here char ch, In fact, it is unscientific , Because at the end of the judgment , Yes. ch!=EOF, and EOF The value of is -1, This is obviously and char It can't be compared . therefore , Some use , We all define it as int ch.
fputc(ch,stdout); // Here's the output to the screen
if(fclose(fp)!=0)
printf("file cannot be closed \n");
else
printf("file is now closed \n");
return 0;
}

C Language ,char Type variables should not be associated with EOF Direct comparison of more related articles

  1. C Language file operation analysis ( 5、 ... and ) And EOF analysis ( Reprint )

      C Language file operation analysis ( 5、 ... and ) And EOF analysis stay C In language , There is a symbol that everyone should be familiar with , That's it EOF(End of File), End of file . But most of the time, the understanding of this is not very clear , This leads to frequent errors when writing code , , ...

  2. C Language char s[] and char *s The difference between

    C Language char s[] and char *s The difference between , The following answer is very clear . The difference here is that char *s = "Hello world" ...

  3. About c Language char One of the types of input and output bug

    subject Enter an integer n, Next n Enter two characters separated by a space on each line . For each pair of characters , Compare the size relation and output the result of comparison :1.0.-1. The solution code is as follows : #include<stdio.h> i ...

  4. c Language char and int The problem of

    Reference resources :http://www.cnblogs.com/dire/p/5222968.html Reference resources baidu: char and int I have a clear definition of , Now there's a problem : 1. set up A and B yes int type ,C yes char type ...

  5. C Language Char* and Char usage

    Category column : C Language   Copyright notice : This article is an original blog article , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement . Link to this article :https://blog.csdn.net/imxlw00/ar ...

  6. c Language char* Type as an intermediate variable to save many strings to an array

    char* It's a string pointer , Like the procedure below value_ As an intermediate variable used in for In circulation scanf The recipient of the entered value , And then value_ Save to array in , But a problem with the program is that when you jump out of this function ...

  7. C Language char[] and char* Compare

    Let's take a look at an example : #include <iostream> using namespace std; main() { char *c1 = "abc"; char c2 ...

  8. C Language char* String arrays and unsigned char[] The mutual conversion of arrays

    #include <iostream> #include <string> using namespace std; void convertUnCharToStr(char* ...

  9. c The function of language enumeration type variable

    #include<stdio.h> enum DAY { MON=, TUE, WED, THU, FRI, SAT, SUN }; int main() { enum DAY day; ...

Random recommendation

  1. SpringMVC Sum up all the way ( One )

    SpringMVC I've heard it for a long time , As early as last year, I was asked about SpringMVC Basic knowledge of , I didn't care . The main reason is that I didn't use it in my work SpringMVC Technology , So avoid the excuse of no time and energy, no contact and no learning Spri ...

  2. Html / CSS common problem Solution

    solve Safari Next input The cursor is too large input { line-height: normal; } Set up a floating layer html, body { /* Only the parent element sets the width and height to 100% The child element sets the width and height 100% It's going to be full when it's time ...

  3. Codeforces Round #338 (Div. 2) A. Bulbs Water problem

    A. Bulbs Topic linking : http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

  4. matlab To judge whether a strictly diagonally dominant matrix can be generated

    As the title : function X = IsStrictDiagMatrix(A) % input: A matrix % output: The matrix after transformation % ...

  5. How to handle jar Add package Maven Local repository

    There are two situations that you need to go through manually Maven The command jar Add files to local warehouse : 1. There's nothing you want in the central warehouse jar package . 2. You wrote one yourself jar package , In other projects . Add : There are still many jar The package does not support Mave ...

  6. COS Respond 7 Big question

    Apple Too closed , No friends , This guy should be more arrogant , Zeng and Intel,IBM and so on.. We played together !Google Too open , evil associates , A flood of friends , bring disaster to ecosystem, The disadvantages are obvious , Disaster is coming .COS Feng ...

  7. First time to know sass frame

    Developers who have written pages know css This thing , The original intention , That is, cascading style sheets , The three structures of our page ,html css javascript, among html Responsible for the main page structure ,css Responsible for the main page styles , And ours js ...

  8. uos The event control block is synchronized with the task

    Ucos Semaphores are defined for communication between tasks , Mutex semaphores , Message object Message queue and so on api, In order to manage these synchronization in a unified way , We define a structure called time control block OS_EVENT, as follows typedef struct os ...

  9. ajax Data request 4(xml Format )

    ajax Data request 4(xml Format ): <!doctype html> <html> <head> <meta charset="utf-8" ...

  10. linux The deployment environment python3+django

    1. determine Linux install C/C++ compiler , Online installation : yum install gcc gcc-c++ autoconf automake 2. Install dependent environment : yum -y install zlib- ...