Question

HELP NEEDED in C++ (preferred) or any other language Write a simple program where you create...

HELP NEEDED in C++ (preferred) or any other language

Write a simple program where you create an array of single byte characters. Make the array 100 bytes long. In C this would be an array of char. Use pointers and casting to put INTEGER (4 byte) and CHARACTER (1 byte) data into the array and pull it out.

Make sure you can access both character and integer data at any location in the array.

Read data from a text file. Pick any random txt file, an article or even the Bible.

Use regular expressions, strtok or any command you want including something you write yourself to break a line of text read from a file into tokens. A token is just a sequence of characters without a separator. The only separator you need is space ' ' but if you want to use more like, comma ',', tab '\t' and semicolon ';' go for it.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ code with delimiters only space using stringstream class

Input (file)

Output

Code with comments

#include <bits/stdc++.h>

using namespace std;

int main() {

  //-----------part 1------------------

  char arr[100]={0};

  int x=1234;

  char ch='A';

  cout<<"Character: "<<ch<<"    Integer: "<<x<<endl;    //print character and integer

  arr[0]='A';

  int i=1;

  string num=to_string(x);  //convert number to string

  for(int j=0;j<num.size();j++) //put string characters in array

    arr[i++]=num[j];

  cout<<arr<<endl;  //print array

  char ch2=arr[0];  //extract char

  int n=0;

  i=1;

  while(arr[i]>='0' && arr[i]<='9'){    //till character is a digit

    n=n*10;

    n=n+arr[i]-'0';

    i++;

  }

  cout<<"Character: "<<ch2<<"    Integer: "<<num<<endl;    //extracted character and integer

  

  //--------------part 2--------------------

  cout<<"------------------------------------\n";

  fstream file;

  file.open("sample.txt");  //open file

  string line;

  getline(file,line);   //read first line from file

  file.close();

  string word;

  stringstream ss(line);

  while(ss>>word)

    cout<<word<<endl;

  return 0;

}

For indentation purpose

Add a comment
Know the answer?
Add Answer to:
HELP NEEDED in C++ (preferred) or any other language Write a simple program where you create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • program should be in c language. thank you for helping me. 1 of 4 CSCI 281...

    program should be in c language. thank you for helping me. 1 of 4 CSCI 281 LAB 5 -STACKS AND A CALCULATOR ASSIGNMENT Using 2 stacks to implement a calculator CALCULATOR 1. User input of two types. Integer values and associated tokens(+ 2. As the user needs to enter the input in the following manner: +5/17-3 9+2 8+7 You should use a looping scanf to allow the user to enter digit, then a char, then a digit, then a car...

  • Please Do it In Java: Objectives: To Java programming language To understand the lexical analysis phase...

    Please Do it In Java: Objectives: To Java programming language To understand the lexical analysis phase of program compilation Assignment: The first phase of compilation is called scanning or lexical analysis. This phase interprets the input program as a sequence of characters and produces a sequence of tokens, which will be used by the parser. Write a Java, program that implements a simple scanner for a source file given as a command-line argument. The format of the tokens is described...

  • JAVA 6. Create two files and name them: puzzle.txt and puzzle2.txt Inside puzzle.txt, write the following...

    JAVA 6. Create two files and name them: puzzle.txt and puzzle2.txt Inside puzzle.txt, write the following text: MWTaahyiebt_e,c__hnyaoontuc;'e_rste_r_aynr_oert_e_gasoduoipdnp_got_shoeandtl__yty_oot_uhrree__apTdrH_oItgRhrDia_sml__eowtnotere.kr_ss_. Inside puzzle2.txt, write the following text: WTTohhriikssi__niigss,___ttbhhueet___wryrioogunh'gtr__emm_eessshssoaawggieen__gff_rrtoohmme___sswaarmmoppnllgee_22o..nttexxstt Open a file specified by the user. This file will contain a bunch of characters. You should read in each character from the file, one character at a time. Display every third character on the screen. Throw the other characters away. There is a sample input file called puzzle.txt, containing a little message you can...

  • USING C LANGUAGE Write a program to compute a Caesar Cipher . You must read in...

    USING C LANGUAGE Write a program to compute a Caesar Cipher . You must read in a file of text and convert some of the letters to another letter using the following array: char key[27] = “efghijklmnopqrstuvwxyzabcd”; This means that if you encounter the letter ‘a’, then you will replace it with the letter ‘e’,etc. If you encounter any other characters in the input file (example: ‘A’ or space, etc, you will write them as is. You will write each...

  • Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from...

    Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from a file named dota.txt that is to be found in the same directory as the running program. The program should ignore al tokens that cannot be read as an integer and read only the ones that can. After reading all of the integers, the program should print all the integers back to the screen, one per line, from the smalest to the largest. For...

  • I'm a bit confused on how to get this program to run right. Here are the...

    I'm a bit confused on how to get this program to run right. Here are the directions: Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed. For example, ‘This line has extra space characters ‘  ‘This line has extra space characters’ Function name: reduceWhitespace Number of parameters: one string line Return value: one string line The main file should handle the...

  • In basic c develop the code below: (a) You will write a program that will do...

    In basic c develop the code below: (a) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘X’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘X’. Example input mJ0*5/]+x1@3qcxX The ‘X’ should not be included when computing the statistics...

  • In this lab, you will write a C program to encrypt a file. The program prompts...

    In this lab, you will write a C program to encrypt a file. The program prompts the user to enter a key (maximum of 5 bytes), then the program uses the key to encrypt the file. Note that the user might enter more than 5 characters, but only the first 5 are used. If a new line before the five characters, the key is padded with 'a'; Note that the new line is not a part of the key, but...

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which...

    //I NEED THE PROGRAM IN C LANGUAGE!// QUESTION: I need you to write a program which manipulates text from an input file using the string library. Your program will accept command line arguments for the input and output file names as well as a list of blacklisted words. There are two major features in this programming: 1. Given an input file with text and a list of words, find and replace every use of these blacklisted words with the string...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT