C++ :: Reading Specific Input Syntax - String Parsing
Apr 21, 2013
I need reading a specific input syntax.
something like
<Input> :: R C <Content>
3
3
.3. .15 9.2
.1. ..6 ...
6.5 7.. ...
... .5. ..9
4.7 .8. 1.6
9.. .6. ...
... ..1 7.4
... 6.. .9.
5.1 49. .3.
View 2 Replies
ADVERTISEMENT
Feb 2, 2015
So imagine you have this string:
"somedata here "some data here" some more data here"
I need to parse this:
somedata here "some data here" some more data here
I tried to do it with Regex and was capable of parsing
[0] = somedata here
[1] = some data here
[2] = some more data here
Here is my current code:
string Buffer = string.Empty;
foreach (Match match in Regex.Matches(strLine, "".*?""))
Buffer = match.ToString();
View 6 Replies
View Related
Oct 1, 2012
So im trying to parse a string into a Ip Address but i have a problem, the IPAddress.Parse method only works for ipv4 address's how do i parse ANY Ip address into a string, if i use the IPaddress.Parse method on my public(remote) IP it throws an exception but on ipv4 local ip it doesn't how do i parse ANY ip address the user inputs as a string as an Ip Address?
View 5 Replies
View Related
Sep 10, 2014
I have been here for almost 3 months looking for answers in my C++ problems.here's some type of code for this.
cout << "Enter value of x: " << endl; //Let's say 5.
cin >> x;
cout << "Enter equation: "; //Let's say x+1
cin >> equation;
Then the program analyzes that this character "x" has an initial value of 5.I already have the parser for the equation functions (+,-,*,/)This is the only thing lacking. Is there some type of function that i missed?
View 6 Replies
View Related
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
Nov 3, 2013
I have an input file that contains any number of lines. Each line will follow the same structure. There will be 5 fields, separated by 4 commas. Fields 1 and 3 will be single characters, fields 2,4,5 will be integers. Example:
<A, 123, B, 456, 789>
I need to iterate over each line, parse out the fields, and capture each field value into a separate variables.
header file: Code: #include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
[Code]....
I've used similar code to this before, but this time I'm getting the dreaded pointer from integer error on my strtok lines:
warning: passing argument 2 of 'strtok' makes pointer from integer without a cast'
View 2 Replies
View Related
Sep 14, 2014
How do I create a function that can understand trigonometric functions?
Examples:
if I am to input: x^2 + sin(x)
The program will understand the the value between parenthesis preceded by a string "sin" will be computed as the sine of x. of any function in case.
I have the program here.
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
using namespace std;
enum types { DELIMITER = 1, VARIABLE, NUMBER }; //DEL = 1; VAR = 2; NUM = 3.
class analyzer {
[Code] .....
View 9 Replies
View Related
Mar 7, 2014
i tried to parse the string data seperated by Pipe('|') delimiter, here i am getting some error.Please find the below code.
[char* getData(){
char* string = "1355|||250|New";
char* tok1[10],tok2[10],tok3[10],tok4[10],tok5[10];
sscanf(string,"%[^'|'],%[^'|'],%[^'|'],%['^|'],%s",tok1,tok2,tok3,tok4,tok5);
printf("%s %s %s %s %s",tok1,tok2,tok3,tok4,tok5);
}]
I want to print the Value 250 in my string, but it was displaying some garbage values.
View 1 Replies
View Related
Feb 23, 2015
I have been skimming and searching but dont know how to word the search just right to find what I need to know. I have written simple stuff with the support of tutorials like weight conversion or loops counting up to a set number. Nothing amazing. The other day I found out how to input and print a string rather than a single text character which i though was bad ass. I even got it to read multiple strings on a single line and found a way to read multiple lines. I can even format it to read both integers and characters on the same line as long as I know the predefined format.
On to my question... How do I read multiple lines with both carecters and integers. for instance:
nissan 1996
toyota 1998
or more comples like
nissan gtr 1996
toyota markii 1998
I want to use
int year;
char make[10]; maybe need to use char make[10][10]; for an array i would guess.
char model[10]; optional for the extra data
but reproduce what i read in a different order. say...
1996 nissan
1998 toyota
vice the original format.
this is what I have tried.
Code: scanf("%s %s", &make,&year);
//The way I seen to read multiple lines was on here
scanf("%[^/t]", %make);
But this wont let me separate the two into two differnet definded data types. Let alone use printf to display them in reverse order.
View 1 Replies
View Related
Feb 11, 2013
In my calculator, I am trying to make it so that you put enter 1 to add, 2 to subtract, 3 to multiply, and 4 to divide. I am facing the issue of making it so that you must enter a number, however instead of it being any number, it must be 1, 2, 3, or 4, and if it is not any of those numbers, you must re-enter the number. Here is a little snippet of my code:
Code:
printf("Please enter 1 to add, 2 to subtract, 3 to multiply, or 4 to multiply: ");
while (scanf("%d", &input) != 1) {
while (getchar() != '
');
printf("Invalid option. Please try again: ");
[Code] ....
how I can make the loop affect specific numbers.
View 4 Replies
View Related
Feb 18, 2014
I have some experience in C# and choose the project of a "rapidfire script". It is a program, which shoot rapidly in a FPS by sending a "left-mouse-button-click" over and over again while the "real" left mouse-button is down.
Now, I tried multiple ways of sending the left mouse button but none of them worked the way I wanted them to. I tried SendMessage, PostMessage and mouse_event. One of them made the window unresponsive, another only pressed the mouse button while I was still moving the mouse and another didn't work at all.
I know a script which does exactly that and is coded in AutoHotKey. AHK is open-source but since I am not familiar with C++, it is very hard for me to understand what exactly is going on here:
AutoHotKey: keyboard_mouse.cpp
And here is the AutoHotkey-Script: AutoHotKey - pastebin.com
And my current code. The input delay is very irregular and strange. Sometimes the real "right mouse button click" gets ignored and I don't know why.
if (State == RapidfireState.ACTIVE) {
// Check if the left mouse button is down. If it is, send fire commands to the game
if (MouseDown()) {
[Code]....
View 2 Replies
View Related
Feb 15, 2013
how can i input lines at a specific area in my file. please provide code
View 3 Replies
View Related
Apr 17, 2015
Here's my code so far:
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int dayNumber = 1;
[Code] ....
The code, when run, prompts the user to input an integer like this:
Code:
Day 1
Andy :>12
Bill :>7
Charlie :>15
Day 2
Andy :>5
Bill :>25
Charlie :>14
.
.
.
etc.
Ok, so the code prompts the user to enter an integer for each of the 3 persons and then increments the "Day" and so on... When the user enters a negative value (-1, -2, etc.), the loop is broken and the program ends. Alright, everything is hunky-dory so far. 2 things which I can't figure out.
1. when the user doesn't enter anything and just hits return, the cursor drops a line and is still awaiting an input but doesn't show the prompt "Andy :>", for example. How can I get it to repeat the last prompt when the user doesn't enter anything? Like:
Code:
Day 1
Andy :>
Andy :>
Andy :>12
Bill :>25
Charlie :>15
.
.
etc.
2. When the user enters a letter or a special character, the program blows up. How can I correct this?
I've tried changing the data type for the variable used for the input, tried using getline, get, etc. With my current beginner knowledge, I'm missing something. So how can I get this to work?
The program should allow only integers to be entered, while allowing a negative number to trigger the loop to break or the program to end, and while re-prompting the last person if the user entered an invalid input.
View 13 Replies
View Related
Feb 4, 2015
i'm doing a validation exercise program. Just a question, how do i search an inputted string for a certain character?
For example:
Hello.World
I wanna determine and find out the where the '.' sign is.
I'm doing an if-else conditions, i need to determine where the character is located and make sure it doesn't repeat.
View 4 Replies
View Related
Feb 23, 2014
Suppose I have to take "100" from the string "1001", whats the process to do it?
View 6 Replies
View Related
Jul 5, 2013
int index = -1;
string NewStr = null;
char[] lower = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char[] upper = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
foreach (char c in str)
[Code]....
The code above loops through a string and for each character checks to see if it is a lower case character, then checks to see if it an upper case. It then removes it if it is. Leaving only the numbers.
However, it reuses the same string the entire time, never updating the string so it always finds the same (first) character.
View 6 Replies
View Related
May 4, 2014
I tried to implement a string class and i want to modify a specific char in my string . I did operator over load but this code crash in this line
name [2] = 'k' ;
Why ?!!!!!!!!!!!!!
this is my code
# include <iostream>
using namespace std;
#include <assert.h>
class String {
public :
char *content ;
int size ;
[Code] ....
View 11 Replies
View Related
Oct 16, 2014
I am attempting to write a recursive function that, given a string, recursively computes a new string where all the lowercase 'x' chars have been moved to the end of the string.
For example,
moveXs("xxre") --> "rexx"
moveXs("xxhixx") --> "hixxxx"
moveXs("xhixhix") --> "hihixxx"
Below is the code I have written thus far, but it seems to be returning only empty strings.
string moveXs(const string& str) {
string strCopy = str;
if (strCopy.length() <= 1) {
return str;
[Code] ....
View 6 Replies
View Related
Apr 3, 2013
I've just recently started to learn C++, and I'm encountering some errors I can't seem to figure out.
InventoryItem.h:
Code:
#pragma once
class InventoryItem {
public:
InventoryItem(string name, int amount);
~InventoryItem(void);
string getName(void);
int getAmount(void);
[code].....
Errors:
Code:
1>d:c++consoleapplicationconsoleapplicationinventoryitem.h(6): error C2061: syntax error : identifier 'string'
1>d:c++consoleapplicationconsoleapplicationinventoryitem.h(8): error C2146: syntax error : missing ';' before identifier 'getName'
[Code] .....
View 14 Replies
View Related
Oct 15, 2013
I am trying to print a specific line from a textfile
e.g
I have a text file called info.txt and inside it contains the id,item name, price, quantity
Code:
1,shirt,100,10
2,pants,50,9
3,pen,20,8
I know how to find a specific word at the line in the file but how do I find and print out the specific line e.g(print out just the entire contents of line 2)?
Code:
string temDescription;
ofstream fout;
int curLine = 0;
[Code].....
View 1 Replies
View Related
Mar 5, 2013
How do I make a specific character show up a specific amount of times?
Like I am generating a random number then I need to make "|" show up that many times on the screen.
View 1 Replies
View Related
Feb 19, 2015
I'm trying to determine the number of times I have to change each specific character in a string to make it a palindrome. You can only change a character one at a time from the end.
Example: "abc" -> "abb" -> "aba" should print 2. "aba" will print 0 because it's already a palindrome. "abcd" -> "abcc" -> "abcb" -> "abca" -> "abba" will print 4 because it took 4 changes to make a palindrome.
I'm not too sure how to approach this - I figured out the case where if it's a palindrome (if reversed string is the same) then it'll print out a 0.
int main() {
int number;
cin >> number; //expecting a number for first line user input
for (int i = 0; i < number; i++) {
string str;
[Code] ....
View 1 Replies
View Related
Feb 25, 2015
I'm trying to make a program that allows the user to input an arbitrary amount of numbers and finding the largest of all the inputs but I keep having problems with the output.
javascript:tx('
#include <iostream>
using namespace std;
//******************************************
//CLASS COMPARATOR
//******************************************
class comparator {
public:
comparator();
[Code] .....
And regardless of what numbers I enter, I always get the output of 10. Also I got the EOF idea from my textbook so if there is a better way of doing this I'd like to hear it. I don't know any clear ways that looks nice to end the while loop when the user doesn't have any more numbers to enter.
View 3 Replies
View Related
Oct 19, 2014
Very new to programming, and I know that there must be another way on inputting a string into each array cells not by just inputting it one by one, but as a whole. My code at the meantime is: [URL]
View 1 Replies
View Related
Feb 16, 2014
I am trying to read from my input file Transactions.data which is set up as follows
V 250190
A 250190 2008 4 8788.00 0.00 000
and so on and so forth.
I am trying to read my V then go to switch (decision) to choose my case and preform further functions. My problem is that i cannot get past the first line so if it was
V 213400
V 123456
My code is supposed to check that the ID (213400) is valid then go on to the next line but it wont do that and prints out the first ID 6 times. My code is as follows:
char descision;
ifstream input;
input.open("Transaction.data");
if (input.fail()) {cout << "File could not be opened." << endl;}
input >> decision;
[Code] ....
View 1 Replies
View Related
Jul 14, 2014
I have problem with string compare. I want to compare the string user input with a string in binary. And I don't know how to do it. Problem in function login();Here is the code: And you also can download file in attachment too..
Code:
#include<conio.h>#include<dos.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
char nsb=1;
char ch, password[20], passlogin[20], inputpass[20], checked[20];
FILE *fp;
}
[code]....
View 1 Replies
View Related