C/C++ :: Scan Through One String To Find A Letter That Also Appears In Another?

Feb 3, 2015

I need a code that will search through string 1 and find the first place with a letter that also appears in string 2 and return the pointer of that place. This is what I wrote:

char strPbrk(const char *s1, const char *s2) {
char p = *s1;
for (int i = 0; i < strlen(s1); i++)
for (int j = 0; j < strlen(s2); j++)
if ((p+i) == *(s2+j))
return p;
return NULL;
}

but it continues to return wrong values idk what I'm doing wrong.

View 4 Replies


ADVERTISEMENT

C++ :: Find Adjacent Same Letter In Randomly Generated String?

Jan 29, 2013

I need a simple adjacent_find() to find the adjacent same letter in a randomly generated string?

View 1 Replies View Related

C :: How To Scan In Numbers From File And Find The Largest

Oct 4, 2013

I'm working on a silent auction program that will scan a file and find the highest from each group of bids, then have a running total of money made throughout the auction. I'm pretty sure the rest of my code works, i'm just getting stuck on finding the largest number from the line in the file, saving it, then moving to the next auction.

input file text (first number is num of auctions, after that it's num of bids, then the bids):

5 4 100 500 250 300 1 700 3 300 150 175 2 920 680 8 20 10 15 25 50 30 19 23

Sample Output
Auction 1 sold for $500.00!
Auction 2 sold for $700.00!
Auction 3 sold for $300.00!
Auction 4 sold for $920.00!
Auction 5 sold for $50.00!

The silent auction raised $2470.00 for charity!

Code:
# include <stdio.h>
# include <stdlib.h>
# include <time.h>

[Code].....

View 4 Replies View Related

C/C++ :: Program To Scan Number And String Then Print Them To A File

Mar 19, 2015

I wrote this program to scan a number and a string until EOF then print them to a file named "data.list". the problem is that the program duplicates last line of input in the output file. so for example if the input is :

1 test
2 dream
3 code

then output (in data.list file) would be:

1 test
2 dream
3 code
3 code

I also changed the program code so that it reads from data.list file. even here it duplicates last line!

so when program reads the info above saved in data.list it would be:

1 test
2 dream
3 code
3 code
3 code

here's the code for writing:

#include <stdio.h>
int main( void )
{
int num;
char str[80];
FILE *fPTR;
fPTR = fopen( "data.list", "w" ); // opens a file named "data.list", create if doesn't exist
while(!feof(stdin)) // loop until End-Of-File is pressed. Ctrl-Z in Windows, Ctrl-D in Unix, Linux, Mac OS X

[Code]...

and the one for reading from file:

#include <stdio.h>
#include <conio.h>
int main( void )
{
int num;
char str[80];
FILE *fPTR;

[Code]...

How do I fix this behavior??

View 3 Replies View Related

C++ :: One Letter Of A String Comparison

Jan 21, 2013

I just would like to turn this into cpp:

string eg("azertyFTW");
if(eg[one of the letters contained in this string] == 'c') {
cout << "eg has the letter c in it";
} else {
cout << "not this time :(";
}

View 4 Replies View Related

C++ :: How To Loop Through A String And Uppercase Each Letter

Apr 28, 2013

tell me how to loop through a string and uppercase each letter?

View 1 Replies View Related

C# :: Capitalize First Letter In Every Word In A String?

Jan 7, 2014

I have a difficulty with string methods for some reason. I tried solving a question from my book, which requires me to capitalize the first letter of every word in a string. I kept trying for maybe two hours yesterday, re-reading the string chapter to see if I'm forgetting a certain method or if something similar was discussed in the examples but I didn't find anything. I also googled it, and found a few answers, none of which I understood. They mostly had keywords or methods I wasn't familiar with. Anyway, here's where I am so far.

class Program {
static string UpperCase(string s) {
int place; string b, st1, st2,st3; char letter;
for (int i = 0; i <= s.Length - 1; i++) {
if (i == 0) {

[Code]....

The code compiles without any errors, but when I enter a string it capitalizes correctly for the first two words and then it starts capitalizing letters in the middle of the words.

View 14 Replies View Related

C++ :: Differentiate A Word / Letter And Number In A String

Aug 22, 2014

I have one string from user. Let say,

"The deviceId is 2"....but user also can give input like this..
"The deviceId is a".

I just need to know how to differentiate a word/letter and number in the string.

View 1 Replies View Related

C++ :: Censor 4 Letter Words String Within Sentence

May 16, 2014

I have a problem with my code. You are given a sentence and you should censor the 4 letter words within the sentence.

#include<iostream>
#include<string>
using namespace std;
int main () {
int N;
cin>>N;
int k,j,counter=0;

[Code] ....

View 1 Replies View Related

C++ :: Input String And Then Convert Each 1st Letter Of Word Into Capital Case

Dec 10, 2014

Write a program that inputs a string and then converts each 1st letter of a word in the string into capital case. An example run of the program is shown below:

Enter string: introduction to programming
Output string: Introduction To Programming

View 1 Replies View Related

C/C++ :: Thread Appears To Run After SetEvent

Apr 28, 2014

I don't know if I've setup the thread correctly or not, but its behavoir isn't what I'd expect. I'm creating the thread within a BN_CLICKED message

typedef struct my_TNFO {
    HANDLE h_event;
    HANDLE h_thread;
    DWORD  thread_id;
    BOOL   running;
    BOOL   init;
    BOOL   canceled;

[Code] ....

progd->count was devised to stop the thread when the recursion ended by posting a message to the main window. When it reaches 1, the def procedure sends the WMU_DISC_DONE message to set the event

All that *appears* to work; however, if I cancel the recursion thread, the list view continues to populate for a bit and then deletels all but 1 item though I send the message LVM_DELETEALLITEMS.

If I move the (tmp->canceled == TRUE) test inside of the do-while, the app gets loopy.

View 4 Replies View Related

C/C++ :: Binary Tree - Count How Often Character (e) Appears In It

Feb 5, 2015

I have a binary Tree and I have to count how often the character 'e' appears in it. Then I have to print it Inorder.

My code:

#include<stdio.h>
#include<stdlib.h>
struct node {
struct node *left;
struct node *right;
char chr;

[Code] ....

But I always get the Error Message "expected ';' ',' '.' or ')' befor numeric constant in this line:

struct node *mkNode(char chr, struct node *1, struct node *r)

View 1 Replies View Related

C :: Number 1 Appears In Next Line Every Time On Typing A Character

May 17, 2014

Everytime I type a character, the number 1 appears in the next line. And i just keep getting the message "Wrong! I have more than that." even when I type a number bigger than 1023

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
srand(time(NULL));

[Code] ....

View 10 Replies View Related

C/C++ :: Dice Rolling - Keeping Track Of How Many Times A Number Appears?

Sep 27, 2014

I wrote a code that mimics a dice, my code so far will ask for the user to input a number at which they want to hold or no longer throw the dice, it will also ask the user how many roll simulations they would like to do.

If a 1 is rolled the turn is over and the score is 0

After this input is recieved the code goes into a loop until the values have been met.

I would to add probability to my code so I need to know how many times a certain number was rolled and this is where I am stuck.

An example of how I would like my code to work, let's suppose hold at number is 17

We role the dice until we roll a 17 or larger, but if we roll a 1, then our score is 0.

Let's suppose the number of simulations is 5 and for simulation 1 we roll

2 + 5 + 6 + 4 = 17

and for simulation 2 we roll

5 + 4 + 1, but since we rolled a 1, the score is 0,

for simulation 3 we roll

3 + 4 + 5 + 6 = 18

for simulation 4 we roll

4 + 4 + 6 + 6 = 20

for simulation 5 we roll

3 + 4 + 5 + 5 = 17 so that means we got

0: 1 time 1/5 = .20
17: 2 times 2/5 = .40
18: 1 time 1/5 = .20
19: 0 times 0/5 = .00
20: 1 time 1/5 = .20
21: 0 times 0/5 = .00
22: 0 times 0/5 = .00

In other words the idea is to roll a 17 or larger (or whatever the hold number happens to be), but if you roll a 1, then your score is a 0.

#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
int dieRoll();

[Code] ....

View 4 Replies View Related

C# :: Option Selection Box To Change What Appears In Main Window Screen

Sep 17, 2014

Basically i have a 'HomeWindow' with a button 'OptionWindow'. My idea is that the 'OptionWindow' button will open up the 'OptionWindow'. Which will give the user three options 'Option1', 'Option2' and 'Option3'. If they pick 'Option1' then in the 'HomeWindow' in a stackpanel i want it to display 'UserControl1'. Where as if they pick 'Option2' then in the 'HomeWindow' in a stackpanel i want it to display 'UserControl2'.

If you need some of my code that i have already then let me know what you need as i have a lot of it so can't paste it all in one go. But the new thing i need is the way of making the user-controls in the 'HomeWindow' change depending on what is selected in the 'OptionWindow'.

View 14 Replies View Related

C++ :: Count How Many Times Each Word Appears - Empty Output Array File

Sep 20, 2014

I am writing this program that is supposed to read a file, put the data into an array, alphabetize, count how many times each word appears and print to an output function. I posted before on how my program had an error when I ran it but I have fixed that. Now my outputArray file is empty. It gets created but there's nothing in it.

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

using namespace std;
//global to this file

[Code] .....

View 3 Replies View Related

C/C++ :: Find If A String Contains A Quoted String?

Oct 23, 2014

bool isQstr(string const& str)
{
size_t found = str.find(""");
return found != string::npos;
}
/*

I am trying to check whether a string contains a quoted string, I used the escape character but it does not even recognize it*/

View 1 Replies View Related

C :: How To Get Scan Code Of ESC Key

Sep 17, 2014

i wrote the following code :

Code:

#include<stdio.h>#include<conio.h>
#include<stdlib.h>
int a[][4] = {15,9,10,25,6,2,4,7,32,19,42,8,21,17,18,0};
void boxes();
void display();
void main()
{int ch,r=3,c=3,t;

[Code]...

not able to esc when i press esc key.how to get rid of this.

View 4 Replies View Related

C :: Scan Value For Specific Data

Dec 13, 2014

I created a program that will create a file and print a list on it. Here is the code for my program:

Code:
int controlvalue(void) {FILE *controlvalue;
controlvalue = fopen("something.txt", "a+");
/* Series of fprintfs */
fclose (controlvalue);
return 1;}

Here is an example list created by my program:

Code:
[Gifts]Candy=45
Chocolate=32
Toy=128
Robot=754
Doll=1492
Star=21
Phone=72
Skateboard=87
Frame=314
Days=365
Perfume=421

I want to get the value of "Skateboard" on file. So I need to read 9 lines. On the 9th line, the gets() loop will stop. But, what if I only want to get the value of "Skateboard" as integer (87) and not a string? Also, is it possible to scan the value of Skateboard if it's located on a different (or unknown) line?

View 1 Replies View Related

C :: How To Scan And Print Integer

Jan 28, 2013

This is my code:

int main() {
int num;
printf("Please enter a number: ");
scanf("%d", num);
printf("%d", num);
return 0;
}

when i compile and run it, it stops working and doesn't printf the integer.

View 3 Replies View Related

C :: Multiple Entries Into Scan?

Sep 19, 2014

How would I be able to let the user enter multiple heart rates which would all be separate.

Code:

printf("Enter your recorded Heart Rates ");
scanf("%d", &in_rate);
//formulas
if (gender == 'm'){
target = 226 - age;
} else if (gender == 'f'){

[Code]...

View 1 Replies View Related

C/C++ :: Scan A Directory Recursively

Dec 19, 2014

I'm writing a C++ module that is meant to recursively scan a directory and I'm curious what yall think of my strategy.

The program is a music player and so I'm trying to make the directory scanner as lightweight and efficient as I can. I've decided I want to scan the files in two passes- first I just want to get a list of all music files that are found in a directory/subdirectories and then I want to process the list and search for id3s/other tags.

As I'm a scanning the directory, I've decided to store the temporary list in a linked list where each node is containing an array of 100 strings. I did this because I obviously don't know how long the list will be and I from my understanding of the C++ vector class it basically just makes over sized arrays and moves them when it runs out of space. That sounded rather clunky to me, as did a traditional linked list.. I didn't see the point of allocating memory that many times in a row.

View 3 Replies View Related

C :: How To Scan Text File And Put It Into Array

Mar 4, 2013

This is my text file.

bak kut teh[tab]888.0[tab]989.0
spicy chicken nugget[tab]999.0[tab]978.0

I'm experiencing some problem in trying to scan and put it into an array for the food names (e.g an array for food which consist of bak kut teh and spicy chicken nugget) and another 2 array for the other individual integer into C. However there seem to be some problem with my code.

Is there a difference if I use both tab and space instead of space for all?

Code:
#include<stdio.h>
int main() {
FILE *fp;
char food[100];
char buff[BUFSIZ];
float num;

[Code] ....

View 2 Replies View Related

C :: Using Fgets() To Scan A Data Before A Delimiter

Dec 21, 2014

Is it possible to fgets() the string (or word) only after a delimiter? I yes then how?

Example: Code: printer, scanner, machine

Also, how can I sscanf() a string with an indefinite number of sizes and assign it to only one variable?

Example:

Code:
str = "I Love C programming 9000";
sscanf(str, "%s %d", strvar, intvar);

View 13 Replies View Related

C++ :: Parallel Scan Of Sorted Sequences?

Feb 4, 2015

I need to take an unknown amount of sorted files and then output any number that is in at least half of them... I know I need to read in the files to a vector and then iterate through them all at the same time looking at the lowest number first and so on. But I am stuck at the point of taking an unknown amount of files and putting them in a container.

This is what I have so far but the vector isn't working and I think I should be putting each file into its own vector.

string get_file(string filename)
{
ifstream in(filename);
if (in)

[Code]....

View 3 Replies View Related

C :: How To Find ASCII Value Of Given String

Aug 25, 2013

I know how to find find ASCII value of given character, but I am not getting how to find ASCII value of given string. For example I want to find ASCII value of string "HELLO",so how to do that.

View 13 Replies View Related







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