C :: Write Text Up To 1000 Characters And Get It Back

Jun 20, 2013

I'm challenged to write a code for the following:

write a text up to 1000 characters, and get it back. the end of the text is detected though EOF on a new line or reaching 1000 characters.(EOF=ctr-Z on a new line)

I mainly have problem how to bring the EOF work probably. it doesn't react when I press ctrl-z directly?

Code:
int i;
char Text[1000];
printf("write the text:
");
gets(Text);
for(i=0;i<=1000;i++){

[Code] .....

View 3 Replies


ADVERTISEMENT

C :: Create File To Write Text And Read Back The File Content

Mar 15, 2013

The Objective Of This Program Is To Create A File To Write Text And Read Back The File Content. To Do That I Have Made Two Function writeFile() To Write And readFile() To Read.The readFile() function works just fine but writeFile() doesn't.

How writeFile() function Works? when writeFile() function Execute It Takes Characters User Type And When Hit Enter(ASC|| 10) It Ask "More?(Y/N)" That Means What User Want? Want To Go Next Line Or End Input?

If "Y" Than Inputs Are Taken From Next Line Else Input Ends.

But The Problem Is When Program Encounters ch==10 It Shows "More?(Y/N)" And Takes Input In cmd variable.If cmd=='Y' I Mean More From Next Line Than It Should Execute Scanf Again To Take ch I Mean User Input.But Its Not!!! Its Always Showing "More?(Y/N)" Again And Again Like A Loop.

Code:
#include <stdio.h>
void writeFile(void);
void readFile(void);
int main(){

[Code].....

View 5 Replies View Related

C++ :: Pushing Characters Back Into The Input Buffer?

Mar 29, 2013

I plan to read one character at a time from a very large text file.

The tokens that I would like to extract are basically words and they are delimited by varying numbers of spaces or tabs.

For example, the first line has two words separated by five spaces:

Joe Mark

Problem:I apply get() each time advancing towards Mark. For me to know ive reached the next token, Mark, I merely have to get() until it equals 'M'. The problem by then its too late as Ive already captured 'M'. I somehow need to capture the fifth space and the code must "know" the next character is 'M' without getting() it.

Kernighan and Richie offer us a function getch() and ungetch() whereby the ungetch pushes back the last character into the input . The problem with this is that I believe is that the buffer is not the actual input buffer stream but rather a simulated character array which contains the input. I dont think itll be as efficient on a text file so large.

View 9 Replies View Related

C/C++ :: Shifting Characters - How To Make Letters Loop Back To The Start

Feb 9, 2015

I have to make a function that i'll later be able to use for a ceasar cypher. The letters should shift a user inputted number. This is what I have so far:

char shiftChar(char c, int s) {
char ch = c;
int shift = s;
int newC;
newC = int(ch) + shift;
return newC;
}

The problem with this, is that it doesn't loop back to the start of the alphabet once i get past z.

View 2 Replies View Related

C++ :: Display Last 1000 Lines From Multiple Text Files (log Files)

Jan 16, 2014

I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.

I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.

What is the best way to do this? Even an outline algorithm will work.

View 6 Replies View Related

C++ :: Text Game - How To Make Player Go Back To Previous Location

Mar 19, 2013

I have started making a text adventure game.

if (Choice == 2) {
cout << "" << endl << "You follow the light to the end of the hallway, you find your self in a room" << endl
<< "with natural light coming from a hole in the ceiling." << endl << "" << endl << "You hear the door you just came through, slam behind you!" << endl << "" << endl
<< "There are three possible directions." << endl << "" << endl << "Do you:" << endl << "" << endl << "1) Go forward" << endl << "" << endl << "2) Go left" << endl

[Code] .....

Ignore the if (Choice == 2) at the beginning, that's linked to some previous code.

I want to make the player go back to the first bit of text but i'm not sure how to do this if they keep choosing to go back and forth from one location.

I first thought of doing it by just putting the text back in after they have chosen the option, but I can't do this infinite times.

View 5 Replies View Related

C++ :: Open A Text File Then Read Data And Print It Back?

Nov 5, 2013

I am in an "intro" C++ course and am having trouble with a section of my current project.

We are required to open a text file, read the data from that file, and print it back.

However, we are supposed to let the user input the name of the file that is to be opened. This is the code I have so far. It is not opening anything.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int NUM_QUESTIONS = 30;
typedef char CharArray[NUM_QUESTIONS];
string fileName;

[Code]...

View 2 Replies View Related

C/C++ :: How To Read And Write Certain Characters From A File

Oct 12, 2014

How to read some characters from file, I know we can move a pointer to some position using seekg() & seekp() function, get current position of the pointer through tellg() & tellp() functions. By moving the pointer to appropriate position using seekg(), we can read the whole line using getline() function. But is there any function which read certain characters from the current position of the pointer and write certain characters from current position of the pointer.

View 1 Replies View Related

C++ ::  How To Read And Write Certain Characters From A File

Oct 12, 2014

How to read some characters from file, I know we can move a pointer to some position using seekg() & seekp() function, get current position of the pointer through tellg() & tellp() functions. By moving the pointer to appropriate position using seekg(), we can read the whole line using getline() function. But is there any function which read certain characters from the current position of the pointer and write certain characters from current position of the pointer.

View 3 Replies View Related

C++ :: Write Program That Outputs The Number Of Characters?

Jun 3, 2013

I need to write a program that outputs the number of characters, words, and lines in the files that are supplied as command-line arguments.

#include <iostream>
#include <string>
#include <iomanip>

[Code]....

View 2 Replies View Related

C++ :: Read String Of Characters And Write With Punctuation Removed

Oct 13, 2014

Write a program that reads a string of characters including punctuation and writes what was read but with the punctuation removed.

This is how i did it:

string x("#punctuation!?=");
cout << x << endl;
for(unsigned i = 0; i < x.size(); ++i) {
if(ispunct(x[i]))
x[i] = ' ';
cout << x << endl;

I am just not sure if thats how they want you to do it because it doesn't remove the punctuations it just replaces them with a space.

View 3 Replies View Related

C :: How To Count Total Characters From A Text File

Mar 21, 2013

I'm supposed to write a program to read a text file and display the following:

a) alphabetic letters //finished with
b) digits // finished with
c) other characters that are not alphabetic letters and not digits //finished with
d) total characters read

The bold part above confused me, by total characters, does it mean the alphabetic letters + other characters? how would I put that in my code?

Code:
#include <stdio.h>
int main (void)
{
int curCh;
int countCh = 0;

[Code]....

View 1 Replies View Related

C :: Possible To Mix Characters And Integer Values In A Text Document

Jul 23, 2013

I was just wondering whether or not it is possible to "mix" characters and integer values in a text document that is to be read by C.

I am to read and use values for length around the hip, neck and such, however, most of the tutoring examples I am finding online seem to strictly deal with either integers or characters alone.

Basically my text file looks a bit like:

Abdominal length: 90.000
Neck length: 26.500
and so on

So, before I move further into this subject, is it possible at all to isolate and use only the double values or will I have to format my text file differently?

View 9 Replies View Related

C++ :: Read Text Write Binary

Feb 4, 2013

I am planning to use this mostly to copy binary files, but why won't this work with text???

input.txt
int main(int argc, char* argv[]) {
// open file
std::ifstream ifs;
ifs.open("./input.txt", std::ios::binary);

[Code] ....

output.txt
310^?z^@^@^@^@^@300367346^A^@

Will this method always work to copy a file?

View 2 Replies View Related

C/C++ :: How To Write Plugins For Text Editor

Nov 21, 2013

I want to add plugins like line numbering, syntax highlighting,code coloring,text alignment in a text editor. How i start including them?

View 1 Replies View Related

C/C++ :: Create And Write To Text File And Then Read From It?

Mar 26, 2014

I have looked through te tutorials here, and even google it, as well as tried to follow the power points from my class..but I still can't seem to figure out how to make this code work correctly.. Basically I have to create a file called grade and write to it a student name and their grade score, and then read from the file all students names and there grade and display this on the screen as well as calculate the grade average for all of the students and display it.

Well I am able to write to the text file, but I can't seem to get the rest to work. I can't figure out how to read from the text file..Here is my code below.

write a sample code that does something similar write to text file string and numbers and then reads from it.

#include <iostream>
#include <fstream>
using namespace std;

[Code].....

View 6 Replies View Related

C/C++ :: 100 To 1000 Divisible By 5 And 6

Oct 2, 2014

Write a program that displays all the numbers from 100 to 1,000, ten per line, that are divisible by 5 and 6. Numbers are separated by exactly one space.

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

[Code]....

View 8 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/C++ :: How To Structure And Write A Class For Text File Streams

Apr 20, 2014

I need to make a program which reads multiple lines from a text file and stores that information in a vector of structs(the vector class template also needs to be custom made).

One of my requirements is to have a class dedicated for I/O for the text file. At the moment I can't seem to get a way to input the data from a file into a vector from an InputOutput class. This is my code:

InputOutput.h

#include <ostream>
#include <fstream>
#include "Share.h"
#include <string>
#include "Vector.h"
class InputOutput {

[Code] ....

This is the menu selection function in the menu.cpp where i figured i would call the Input file and store it from case 1. I think I'm doing it wrong though. Is there a better way of doing this because at the moment i am getting some errors such as error LNK2019.

void Menu::UserMenuSelection() {
Vector<Share> shares;
std::ifstream infile;
switch (menuOption) {

[Code] ....

View 2 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/C++ :: How To Write Class Objects To Text File Using Fstream

Jan 15, 2014

I need to a simple example for writing class' objects to a text file using fstream , I tried to search the forums and I found binary examples but not for to a text file.

View 8 Replies View Related

C/C++ :: Simultaneous Reading And Write From And To Text File Using Multithreading

Feb 13, 2013

Simultaneous Reading and write from and to a text file using Multithreading in c/C++

View 1 Replies View Related

C Sharp :: Open New Cmd From Console Application And Write Text

Oct 23, 2012

I want to open one new CMD from console application, write text into the new CMD and then coming back to the control on the old cmd. (like interactively working on the both)

look into the below code

Process P1 = Process.Start(@"C:WINDOWSsystem32cmd.exe");
P1.StartInfo.RedirectStandardInput = true;
P1.StartInfo.RedirectStandardOutput = true;
P1.StartInfo.UseShellExecute = false;
StreamWriter wr = P1.StandardInput;
wr.WriteLine("First line in New Cmd");
Console.WriteLine("First line in Old Cmd");
wr.WriteLine("Second line in New Cmd");
Console.WriteLine("Second line in Old Cmd");

it is giving the exception "StandardIn has not been redirected"

View 1 Replies View Related

C++ :: Write Interactive Text Based Menu Interface (using A Loop)

Sep 27, 2013

Write an interactive text based menu interface (using a loop) that will allow the user to

Enter a task or assignment Display all of the tasks that are in the file Find a task by Course Quit For each task, you need to keep track of:

Course Name that it is for (e.g., CS162)
Description of the assignment (e.g., Finish Lab 2)
Due date (e.g., 9/26/2009)

Allow the program to keep looping until user wants to quit. When the program starts, it should load the tasks from external file ("tasks.txt") into memory. When user enters the three items of a task, the program needs to read them in, save them in memory and eventually write them to the external data file ("tasks.txt"). The file format could look like: (The ';' is used as a delimiter or field seperator.)

Some Implementation Requirements:

Write at least four functions WITH arguments for this assignment. Use struct named Task to model task Use array of structs to model the collection of tasks. Hint: In this assignment, the description and course name may have multiple words in it. Therefore, you now SHOULD read using the 3 argument version of get. Watch out. When using the 3 argument version of get you need to make sure to remove the delimiter or newline. Therefore, anytime you read (even a confirmation message), make sure to eat the newline! Make sure to have a delimiter written between each item in the file – like a newline. This will be important when you read the information back from the file.

This is my code so far:

#include <iostream>
int main()
{
char cname[25],desc[20];

[Code]....

View 1 Replies View Related

C++ :: Find All Prime Numbers From 1 To 1000?

Jan 9, 2013

#include<iostream>
#include <cstdlib>
using namespace std;

[Code].....

View 10 Replies View Related

C++ :: Display All Composite Numbers From 0 To 1000?

Feb 21, 2013

Create a program that will display all the composite numbers from 0 to 1000 and has a maximum column of 5 . A composite number is a positive integer that has at least one positive divisor other than one or itself. In other words a composite number is any positive integer greater than one that is not a prime number.

SAMPLE OUTPUT:

4 6 8 9 10
12 14 15 16 18
20 21 22 24 25
26 27 28 30 32
....and so on.

View 6 Replies View Related







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