This is one:
What that really does is this:
That's a big difference.
Note also that getchar() returns an int, not a char. So you can't read the valid character input that corresponds to the truncated integer value of EOF, whatever that value happens to be on your system.
Also, you're not properly initializing your lastChar variable, so you never know what you're comparing it too when you start. Because you could read any character from the stream, your lastChar variable should probably be an int instead of a char, and you could initialize it to something like EOF to make sure it starts with a value that isn't a valid char value.
Not only that, you're doing an assignment instead of a comparison in your if statement. This:
should be:
I'd do something like this:
You will note that I deliberately avoided placing ANY assignment statement inside a conditional clause. Most compilers in my experience provide for a warning when they encounter an assignment in a conditional clause. If you make a point of never putting assignment statements in a conditional clause, you can then use that warning capability to find and fix mistakes in your code.
Because you will make mistakes when you code. Anyone who says they write mistake-free and bug-free code is lying or deluded, plain and simple.
Note also that I always used { and } after my conditional clauses. Always using braces even for one-line conditional code makes mistakes like the one you made with your while-loop impossible to make.
Don't pay attention to how code is laid out in textbooks. In textbooks, whitespace and extra lines cost the publisher money.
Hello. First time poster here. I have a huge file of IP numbers. I am trying to output only the class b of the IPs and rank them by most common and output the total # of duplicate class b's before the class b. An example is below:
12.107.1.1
12.107.9.54
12.108.3.89
12.109.109.4
12.109.6.3
... (2 Replies)
I was using the following bash command inside the emacs compile command to search C++ source code:
grep -inr --include='*.h' --include='*.cpp' '"' * | sed "/include/d" | sed "/_T/d" | sed '/^ *\/\//d' | sed '/extern/d'
Emacs will then position me in the correct file and at the correct line... (0 Replies)
I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :(
I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
I'm new at this script stuff... only have minor exposure to java.
My problem is largely syntax and being unable to figure out what the manuals are telling me what each option does. Basically I have a hard time understanding the documentation and need help with what awk is capable of on the shell... (4 Replies)
Hi,
I have a very big (with around 1 million entries) txt file with IPv4 addresses in the standard format, i.e. a.b.c.d
The file looks like
10.1.1.1
10.1.1.1
10.1.1.1
10.1.2.4
10.1.2.4
12.1.5.6
.
.
.
.
and so on....
There are duplicate/multiple entries for some IP... (3 Replies)
Hi,
In a file, I have to mark duplicate records as 'D' and the latest record alone as 'C'.
In the below file, I have to identify if duplicate records are there or not based on Man_ID, Man_DT, Ship_ID and I have to mark the record with latest Ship_DT as "C" and other as "D" (I have to create... (7 Replies)
Dear folks
I have a map file of around 54K lines and some of the values in the second column have the same value and I want to find them and delete all of the same values. I looked over duplicate commands but my case is not to keep one of the duplicate values. I want to remove all of the same... (4 Replies)
Hi Team,
I have a file a1.txt with data as follows.
dfjakjf...asdfkasj</EnableQuotedIDs><SQL><SelectStatement modified='1' type='string'><!
The delimiter string: <SelectStatement modified='1' type='string'><!
dlm="<SelectStatement modified='1' type='string'><!
The above command is... (7 Replies)