C :: Write Text And Find Frequency Of 1 Chosen Character In It - Input Error Handling

Dec 20, 2014

I'm new in programming, and trying to write a code in C. The requirement is following - to write a text, and to find frequency of 1 chosen character in it. The main thing is that program should check user input (for example, I want to check if user entered "char" --> then correct, or if entered "int" --> not correct). But the program still doesn't check. So I have:

Code:
#include <stdio.h>
int main(){
char c[1000], ch;
char i, count=0;
printf("Enter a text: ");
gets(c);

[Code] ....

Am I on my right way using if/else?

View 3 Replies


ADVERTISEMENT

C :: Find Highest Frequency Character In A String

May 17, 2014

The code shows all characters frequency, however i want to find which one has highest frequency

For example cprogrammmmming cboard
highest frequency: m

Code:
char string[100], ch;int c =0, count[26]={0};
printf("Enter a string
");
gets(string);

[Code] ....

View 3 Replies View Related

C++ :: Data File Handling Error - Character Strings Not Copied On Text File

Nov 24, 2013

I have this code for a computer project... (store management) but the character strings are not copied on text file..

#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class Store {
public:
char *item_name[5];
store()

[Code] .....

Now when i run the program, it gives a error :::
ERROR
address 0x0

How can i write these strings to the text file?

View 2 Replies View Related

C/C++ :: Finding Highest Frequency Character In A String?

May 17, 2014

the code shows all characters frequency, however i want to find which one has highest frequency for example cprogrammmmming cboard highest frequency: m

char string[100], ch;int c =0, count[26]={0};
printf("Enter a string");
gets(string);

[Code].....

View 8 Replies View Related

C :: Syntax Error At The End Of Input And Warning (multi-character Constant)

Feb 18, 2013

Here's my code. The error's at the last line.

Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define max_con 30

void add_contact();
void edit_contact();
void del_contact();
void list_contact();

[Code] .....

View 6 Replies View Related

C++ :: Find Frequency (string Into Struct Array)?

Apr 17, 2013

I'm trying to figure out the word frequency of a user inserted string. I've tried doing it via getline of the struct array and via the getline of the string word but neither either the former crashes or the latter just prints out the whole string.

Here is the latter.

#include "stdafx.h"
#include <iostream>
#include <string>
#define MAX_WORDS 200
using namespace std;

[Code] ....

How to handle the array of structs.

View 5 Replies View Related

C :: How To Write A Program To Make The User Input With Text

Sep 22, 2013

I need to write a program to make the user input some text, and the first letter of each word has to be uppercase. (have to use while loops)

So for example lets say the user inputs:

i lOvE pRoGrAmMiNg

The output needs to be:

I Love Programming

Code: int main()
{
char c, lower_c;
printf("Enter Text");
while (c != '' && c >= 0)
{
if (c >= 'A' && c <= 'Z')
lower_c = c + 32;
else
lower_c = c;

[Code]...

I have started this code by making the letters lowercase (I don't know if this was the right way to approach this, ). I am not sure how proceed after this step, the step of making the first letter uppercase. (PS for the program, loops should be while loops)

View 6 Replies View Related

C++ :: Write A Program That Opens Two Text Files For Input?

Nov 23, 2013

I am trying to make a simple program, I would like it to be able to do the following, Write a program that opens two text files (input1.txt and input2.txt) for input .The program should write the followings in the two files. input1.txt:

This is the first line in input1.txt.
This is the second line in input1.txt.
This is the third line in input1.txt.
This is the fourth line in input1.txt.

input2.txt:

This is the first line in input2.txt.
This is the second line in input2.txt.
This is the third line in input2.txt.

What would be the best way to go about doing this? I wrote the program below, but I don't think that it works.

#include <iostream>
#include <fstream>
#include <string>
int main()
{
using namespace std;
string input1;

[Code]...

View 2 Replies View Related

C++ :: Word Frequency In A Text

Dec 7, 2013

This program counts how many times does a word appear in a text. Why i have to add 1 to p in the while loop?

#include <iostream>
#include <cstring>
using namespace std;
char s[200], c1[20], *p;
int main() {
int k=0;

[Code] ....

View 1 Replies View Related

C/C++ :: Write A Program That Reads Four Float Numbers From The Input Text File

Apr 3, 2015

I need to write a program that reads four float numbers from the input.txt file, then it prints out the greatest of the four numbers into the output.txt file. I did everything, but the numbers don't print out.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile;
ofstream outFile;
float number1, number2, number3, number4;

[Code]...

View 2 Replies View Related

C++ :: Multi-character Character Constant Error Message?

Sep 14, 2014

I keep getting this warning message and I do not know how to fix it. Is it because I'm using char to instead of strings to replace all 't' with 'lp'?

#include<iostream>
#include<string>
#include <stdio.h>
using namespace std;
char * scanf(char * a) {

[code]....

View 6 Replies View Related

C++ :: Reading Data Character By Character From Text File

Jul 25, 2012

Double values are stored in text file. 23.5 36.8 34.2 ... My teacher told me to read them character by character and then make words, like i have to read "2" "3" "." "5" and now have to make it or treat it as word and then using atoi(). I have to convert it into double. but i dont know how to do this....

View 5 Replies View Related

C/C++ :: Read Input File Character By Character?

Aug 10, 2012

How do I write an a program that will read an input file character by character?

View 1 Replies View Related

Visual C++ :: Unable To Find Setting For Exception Handling In MFC

Jan 24, 2013

My MDI Project(VC++2010 Professional) is unable to catch errors ,though I return ,try catch block. So I developed simple dialog based application .Placed one button on Dialog and on its click written following code

Collapse | Copy Code
void CMFCExecDlg::OnBnClickedButton1() {
try {
int j = 0;
int i = 10/j;
}
catch(CException * e) {
MessageBox(_T("Hello"),_T(""),MB_OK);
}
}

But still program control does not come in catch block it simply gives error. I tried all child classes of CException but no use.I think there will be some setting in Visual Studio. How to handle exceptions

View 1 Replies View Related

C++ :: Error Handling When Using Boost NonCopyable

Aug 2, 2014

I have been using a Boost NonCopyable library in Microsoft Visual Studio 2013.

What I have is the following error message:

Error1error C2280: 'boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable &)' : attempting to reference a deleted functionc:usersjohndocumentsvisual studio 2013projectsdonttreaddonttreaddonttread.cpp181DontTread

Now what I want to rectify the error is to throw an exception, so that the program can compile smoothly.

View 4 Replies View Related

C/C++ :: How To Do Error Handling In Predictive Parser

May 9, 2014

#include<iostream>
using namespace std;
void E();
void T();
void F();
void match(char m);

[Code] ....

I have written this code for predictive parser. It is working for valid input but it is not working for invalid input when i give invalid input it says its valid. How to do error handling in predictive parser.

View 3 Replies View Related

C/C++ :: Declaration Syntax Error Handling

Jan 30, 2015

void main() {
     clrscr();  
     cout<<" Menu";
     cout<<"
1. Display all the employees' info.";
     cout<<"
2. Display specific employes' info.";
     cout<<"
3. Display employee with max salary.";

[code]....

Declaration syntax error at line 89, I don't get this everything is proper.

View 1 Replies View Related

C/C++ :: Error Handling For File Opening And Reading

Apr 23, 2014

I am writing to write a program and performs the following tasks

- Reading a file (txt file contains some temperature values)
- Display the temperature values (contents of the file)
- Calculating the average of the temperature values in the file.
- finds the maximum and minim value of temperature in the file.

The program is user interactive and waits for the user input and process according to his input (choice)

I have managed to complete the program and covered all the expect except the error handling for file opening and reading, although I have managed to do it for the part one part (i.e for the choice == 1)

I can repeat it for the other choices (i.e for 2, 3 ) but I do not want to repeat the code and do it in a different function or do it once for all. While making an attempt I can not handle the rest of the program and all the program turns into a mess.

#include <iostream>
#include <fstream>
#include <iomanip>
int menu();
int myChoice(char);
char inputValidating();

[Code] .....

Need Error handling for file opening and Reading that is used once, So far I have managed to do it for choice 1

Text file can be found in the attachment

View 3 Replies View Related

C++ :: Error Handling - Enigma Cipher Simulator

Jan 4, 2014

I finished my Enigma cipher simulator...how should I write the error handling code? Should I throw an exception in main, or in the Enigma ctor and Encrypt() fn when the user enters a non-alphanumeric character?

Rotor.hpp

Code:
#ifndef ROTOR_HPP
#define ROTOR_HPP
class Rotor {
public:
Rotor(char pos='A');
Rotor(const Rotor & rhs);
Rotor& operator=(const Rotor& rhs);

[Code] ....

Output

Code:
Enter rotor settings:
ABCDEFGHIJ
Enter cleartext:
HELLO WORLD
Ciphertext:
0O258 SGY5V

View 3 Replies View Related

C++ :: Templates (composition) Exception Handling Run-time Error

Aug 4, 2012

The code is compiled.

If I do loops for push and pop fucntions in main.cpp the same size as Stoke everything is working properly

If loops are larger than the Stack size that goes here is a picture in the console (see screen print)

Code:
//
//(---.Array_hpp---)
//
#ifndef Array_HPP// Preprocessor gates
#define Array_HPP
#include <sstream>
#include <iostream>
#include <exception>
template <class Type>//Remove the "=double" default parameter.

[code]....

View 4 Replies View Related

C++ :: I/O Text File Handling And Dynamic Memory Allocation

May 19, 2014

I am working on an OOP assignment (text handler) which part of its description is:

Some lines of text as a story which the delimiter between each story is %%%%%

Each text loaded should only occupy the space needed for the text to fit.

It's required to use dynamic variables of type char*. To be more detailed, the text-handler must contain a vector of such char-pointers (i.e. c-strings), and the parameter in the constructor indicates how many pointers (c-strings) to be contained in the vector. Each loaded text will be represented by a number, so that the first text in the file gets number 0 and the next one gets number 1 ... etc. When you want to access a text, you request the text with a certain number, and then get a pointer in return that may be used to output the text on the screen.

My problem is first to allocate a dynamic memory like char** without defining the number of array elements (Each text loaded should only occupy the space needed for the text to fit. )and then store each story from text file (comprise of a few lines of text) into that dynamically located memory(char **)to be able to do some operation on it later.

View 15 Replies View Related

C++ :: Write Program That Ask His Or Her Name And Store It In Character Array

May 28, 2013

write a program that ask his or her name and store it in a character array

View 1 Replies View Related

C :: Find Character Position - Output 0

Jul 8, 2014

I try to find charecter position but evey time i run my program it give me 0 position why ? Why in my getChar function give me warning statement with no effect i can not understand this warning where is my mistake.

Code:
void getChar(const char* str){
int lenStr = strlen(str);
int i = 0;
int posCharecter = 0;
printf(" %s has %d charecters length
",str,lenStr);

[Code] .....

View 2 Replies View Related

C++ :: How To Find Position Of Certain Character In String

Jan 11, 2013

I need to find position of certain character in string, so i made a function but it doesn't do what i thought it would.

Consider this string:

std::string line = "<foo> <foo> <foo> <foo> <foo>"

I need to find position of a third '>' character so i can get:

std::string other = "<foo> <foo> <foo>";

This is my function that fails:

std::size_t find_third(const std::string& line) {
std::size_t pos = 0u;
for(std::size_t i = 0; i < 3u; ++i) {
std::string tmp = line.substr(pos);
pos = tmp.find_first_of('>');
} return pos;
}

View 6 Replies View Related

C/C++ :: Getting Header Error C2447 / Can't Find Error Source

Sep 8, 2014

Cannot manage to find the error source when i try running the program, the first part of the program runs just fine its when i try to get the temperature one that i get the error

#include <iostream>
#define pi 3.141592
using namespace std;
int main() {
double r, h; //declare variables for radious and height
double Surfacearea;

[code]....

View 1 Replies View Related

C/C++ :: Program To Find Index Of Character In A String Gives Incorrect Output

Oct 28, 2014

I've been typed out a C program to let the user define the size of their string , and key in characters for this string , the program would then prompt the user for a character to search for in the string and return it's index value. Eg. Index of c in abc is 2. My code is as shown:

#include<stdio.h>
#define SIZE 20
int search(char x[SIZE+1] , int n , char s);
int main(void){
char x[SIZE+1] , s;
int n , index;

[Code] ....

However , after I key in my characters for the string , the program does not prompt me to input a character to look for, it just prints it out and returns some funny number. But the program works just fine is I move this portion to the top :

printf("Enter alphabet to find: ");
scanf("%c",&s);

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved