473,748 Members | 10,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count the letters and sequence from a file

11 New Member
the problem is to count the letters and sequence from a file. the fist thing of my code is to read file and in the main function i create is to count the characters and sequence by using 2 dimension array.
where the character include letters and spaces.
I am just learning c language at the moment, i have problem with following program:
#define TRUE 1
#define FALSE 0
#define MAX_LENGTH 100000 /* Max number of chars read from file */
#include <stdio.h>
#include <ctype.h>

int Get_String_From _File(char filename[], char input[])
/* Reads in characters (including \n) from a file as one long string */
/* filename should give name of an existing file;
input will return contents of that file */
/* Return value 0 if file open fails, 1 otherwise */
/* Maximum length of string is stored in MAX_LENGTH */

{
int i = -1; /* will be updated before being used */
char temp;
FILE *infile;

infile = fopen(filename, "r");
if (infile == NULL) {
printf("Failed to open file \"%s\"\n",filen ame);
return FALSE;
}

do {
i++;
input[i] = fgetc(infile);
} while (input[i] != EOF && i < MAX_LENGTH - 1 && input[i] != '\0');
if (i == MAX_LENGTH - 1) /* only reason for stopping is MAX_LENGTH */
fprintf(stderr, "Warning: Reached maximum size of file handled by this program!\n\n");
input[i] = '\0'; /* end of string marker*/
fclose(infile);

return TRUE; /* Successfully read file */
}
int main(void)
{
int c, i, j, spaces,charArra y[26][26];

for (i=0; i<26; ++i) /* init array to zero */
charArray[i][j] = 0;
for( j= 0; j<26; ++j)
charArray[j] = 0;
while((c = getchar()) != EOF) /* count the letter */
if(isupper(c) && islower(c))
++char[c -> 'A' && c -> 'a' && c->’ ‘];
for (i=0; i<26; ++i)
if(i%6==0)
for ( j= 0; j<26; ++j)
if(j%6==0) {
printf("\n");
printf("%4c%4c: %3d%3d", 'A' || 'a' +i +j, letter[i][j]);
}
printf("\n\n");
return 0;
}
Oct 29 '06 #1
0 2294

Sign in to post your reply or Sign up for a free account.

Similar topics

5
7652
by: jester.dev | last post by:
Hello, I'm learning Python from Python Bible, and having some problems with this code below. When I run it, I get nothing. It should open the file poem.txt (which exists in the current directory) and count number of times any given word appears in the text. #!/usr/bin/python
12
8228
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I not - be able to use non-ASCII characters in strings and in Tk GUI button labels and GUI window titles and in raw_input data without Python returning wrong case in manipulated
9
22103
by: dan | last post by:
this is a program to count average letters per word. i am able to count the total number of letters, but not words. How do you count the total number of words in a text file, so i am able to divide the total letters divided by words. #include <iostream> #include <fstream> #include <cstdlib> #include <cctype>
7
9698
by: Dung Ping | last post by:
Such as: <script> //code aaaa zzzz ccc
4
3159
by: Bo Peng | last post by:
Dear list, I am looking for a way to store a large amount of unique sequences that will be accessed by objects. The most important operations are: 1. Direct access to the sequences (from pointers stored in each object). Access through key lookup is not acceptable. 2. Given a new sequence, determine if it is already in the factory of sequences. If so, increase the reference count of the existing sequence
68
6826
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
9
2776
by: MLH | last post by:
A mailing list table in its virgin state contained sequential, consecutive integers in an autonumber field (A97). I've deleted records throughout the table. Now I would like to identify each skipped number. Hmmm??? If I'd had a boolean field named , I could-a-check-marked it and they would-a-been much easier to count. How could I determine that 3 numbers were missing from the following sequence: 1 2 4 5 7 9 and record those...
16
4436
by: lovecreatesbea... | last post by:
It takes mu so time to finish this C source code line count function. What do you think about it? / ******************************************************************************* * Function : size_t linecnt(char *filenm); * Author : jhlicfoocbar@gmail.com, remove foobar for email * Date : 2008.4.12 * Description: C source code line count. No comments & no space lines
4
2687
by: abueno | last post by:
//It should count how many characters are letters in the English alphabet, and is displaying the correct letters, but is not counting good. void FunctionCountLetters(char s) { int len; int i; len=strlen(s); cout<<"\n The lenght of the string is= "<<len<<endl;
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.