Sponsored Content
Top Forums Programming Bug in "Word Counting" Program Post 302620043 by Corona688 on Friday 6th of April 2012 09:27:47 PM
Old 04-06-2012
Every time a letter is in a word and is not whitespace, you add 1 to wc. That happens twice when you type in ab.

I'd use a few loops:
Code:
#include <stdio.h>
#include <ctype.h>

int main()
{
        int wordcount=0;

        while(!feof(stdin))
        {
                int c;
                while(isspace(c=fgetc(stdin));

                if(c < 0) break;
                wordcount++;

                while(!isspace(c=fgetc(stdin)))
                {
                        if(c<0) break;
                }

                if(c<0) break;
        }

        printf("wordcount %d\n", wc);
}

 

8 More Discussions You Might Find Interesting

1. Programming

how could i make a program mixed with many "|", "<" and ">"

I have written following code to do: ls -l | wc -w, it works: but when there are not only a single "|", if there are more such as: ls -l | sort -r | sort | sort -r, This program does not work, i want to know how could i deal with it when there are more "|", another situation is that, if it mixes... (2 Replies)
Discussion started by: strugglingman
2 Replies

2. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

3. UNIX for Dummies Questions & Answers

Counting vowels in string. "Comparison pointer-integer".

I'm trying to write a programme which scans strings to find how many vowels they contain. I get an error saying that I'm trying to compare a pointer and an integer inif(*v == scanme){. How can I overcome this ? Also, the programme seems to scan only the first word of a string e.g.: if I type "abc... (1 Reply)
Discussion started by: fakuse
1 Replies

4. Cybersecurity

Tor Browser Bundle for Linux (2.2.35-8) "EVIL bug"

There is an EVIL bug in at least the Linux (2.2.35-8) Tor Browser Bundle start-tor-browser script. It will log things like domain names to a file in the root of the browser bundle. trac.torproject.org/projects/tor/ticket/5417 Ticket #5417 (new defect) RelativeLink.sh in Tor browser bundle... (0 Replies)
Discussion started by: madeinindia
0 Replies

5. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

6. Shell Programming and Scripting

Please identify "unexpected end of file" bug

This is a script I got off the web for transferring Safari's "reading list" to the Pocket app. I ran it in terminal with the command bash exportsafarireadinglist.sh and got syntax error: unexpected end of file. Thanks for any help! The code: #!/bin/bash # Script to export Safari's reading... (2 Replies)
Discussion started by: kdog126
2 Replies

7. Shell Programming and Scripting

How do i replace a word ending with "key" using awk excpet for one word?

echo {mbr_key,grp_key,dep_key,abc,xyz,aaa,ccc} | awk 'gsub(/^|abc,|$/,"") {print}' Required output {grp_key,xyz,aaa,ccc} (5 Replies)
Discussion started by: 100bees
5 Replies

8. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
DH_BUGFILES(1)							     Debhelper							    DH_BUGFILES(1)

NAME
dh_bugfiles - install bug reporting customization files into package build directories SYNOPSIS
dh_bugfiles [-A] [debhelperoptions] DESCRIPTION
dh_bugfiles is a debhelper program that is responsible for installing bug reporting customization files (bug scripts and/or bug control files and/or presubj files) into package build directories. FILES
debian/package.bug-script This is the script to be run by the bug reporting program for generating a bug report template. This file is installed as usr/share/bug/package in the package build directory if no other types of bug reporting customization files are going to be installed for the package in question. Otherwise, this file is installed as usr/share/bug/package/script. Finally, the installed script is given execute permissions. debian/package.bug-control It is the bug control file containing some directions for the bug reporting tool. This file is installed as usr/share/bug/package/control in the package build directory. debian/package.bug-presubj The contents of this file are displayed to the user by the bug reporting tool before allowing the user to write a bug report on the package to the Debian Bug Tracking System. This file is installed as usr/share/bug/package/presubj in the package build directory. OPTIONS
-A, --all Install debian/bug-* files to ALL packages acted on when respective debian/package.bug-* files do not exist. Normally, debian/bug-* will be installed to the first package only. SEE ALSO
/usr/share/doc/reportbug/README.developers.gz debhelper(1) This program is a part of debhelper. AUTHOR
Modestas Vainius <modestas@vainius.eu> 11.1.6ubuntu2 2018-05-10 DH_BUGFILES(1)
All times are GMT -4. The time now is 03:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy