C++ :: Comparing Chars In A While Statement
Jul 1, 2014
I am trying to do this but it can never seem to work.
#include <iostream>
using namespace std;
int main () {
char charOne;
cin.get(charOne);
cin.ignore(1000, '
[Code] .....
Basically i want to keep looping until i enter an a or A (also does this apply to if statements as well?)
View 6 Replies
ADVERTISEMENT
Aug 31, 2014
i actually i want store string in r and try to compare other string (room_no) in function check but i try many time it still having error
#include<iostream>
#include<conio.h>
#include<fstream>
[Code].....
View 2 Replies
View Related
Oct 25, 2014
The issue that I'm having is that when I run this part of the code it seems to enter the if statement and set it to 0 when comparing the array to the input.
What I want it to do is to search the array for the grade, set it to zero, and then exit the loop in case there are any repeat grades. It always sets the first number to 0 and then exits.
//Below is the prototyping for the array
int grades[14] = {60,50,50,20,75,90,0,0,0,0,0,0,0,0};
//There is some code between here, but it is probably not relevant so I didn't post it.
printf("Enter the grade that you want to remove. Press Enter after each input.");
printf("Enter 0 to exit: ");
[Code] ....
I didn't mean to leave the "prototyping" part in the code. I was initially going to put the function prototypes in there, but decided it wasn't necessary for the question.
View 6 Replies
View Related
Sep 7, 2013
How to make if else code below into SWITCH STATEMENT?
cout << "Enter the temperature: ";
cin >> temp;
cout << "Enter the pressure: ";
cin >> pressure;
cout <<endl;
[Code]....
View 6 Replies
View Related
May 20, 2013
I'm looking for a algorithm to search portions of string that have the same caracter. The only possible values are: a,n and g
Char index: 0 1 2 3 4 5 6 7 8 9 RESULT
------------------------------------------
Example 1: a g g g a a 0,4
Example 2: g g g a n n a 0,3
Example 3: a g g g g g g a 0,7
Example 4: g g g g g g g 0,6
Example 5: g g a a g a a a g 0,2,3,5,7,8
View 4 Replies
View Related
Sep 23, 2014
This is for homework . Must use only getchar and putchar
Code:
int main(void) {
int pch; //first
int ch; //second
[Code]....
And it works , but i need to hit ENTER two times when i have 3,5,7... chars to print result.
View 6 Replies
View Related
Apr 13, 2013
I'm working on a homework project, and it requires me to read in a file of chars into an array, and then do stuff with that array.
Anyways, I have the first part written, where I'm just trying to read in my data.txt file, and I thought I had it written well. It compiles, but then it seg faults, and I'm not sure why. I used calloc for the array, but maybe I misused it? Or is it in my EOF statement? I'm still not sure if that's coded correctly. I need to get past this so I can start testing the other parts of my code.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[] ) {
/* Local Declarations*/
int i;
int *ptr;
char tempc;
[Code] .....
View 1 Replies
View Related
Sep 27, 2013
I am trying to convert some chars to UTF-8 strings...
Example:
std::string gethex(char c) {
/* EXAMPLE
if (c == 'é')
return "%c3%a9";
I need a function that converts chars like "á, é, í, ã" to UTF-8 hexadecimal strings...
*/
}
[Code] .....
[URL] .... does it. Choose UTF-8, type some character and click 'Url Encode'.
View 14 Replies
View Related
Apr 10, 2014
I'm trying to put in my messages, in my program, some special chars but when i try something like the following code, i get the output below.
#include <stdio.h>
int main( ) {
printf("Trying this char: %c", 160);
printf("Trying this char: %c", 163);
return 0;
}
Output:
Trying this char: �
Trying this char: �
How can i put those special chars? I would like to use: é, ú, ç, à, Ú, À, ...
View 14 Replies
View Related
Feb 10, 2014
I'm writing a school assignment that writes/reads user input into and out of a binary file.
I've gotten the write part to work, but now I need to be able to read that file back in and display it as a string.
I think I should be using fread() and read my file into an array of int's right? But when I try printing out that array I get a whole bunch of numbers that don't match the hex code in my file.
How do I read in a binary file and print it out as a string?
View 4 Replies
View Related
Aug 7, 2014
I have a problem with my code. I just have to reverse the chars of a string, but it adds a /n that I can't delete.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ch05Ex05._5 {
[Code] ....
View 5 Replies
View Related
Mar 31, 2012
I found this method
Code:
TCHAR win_getch()
(below) on a website which is used for printing the characters as the keys on keyboard are hit i-e without hitting the ENTER key. This method is used in a while loop like this
Code:
while ((c = win_getch()) != 13)
{}
I wanted to know why is the character compared to
Code:
13
i-e
Code:
if((c = win_getch()) != 13) then do something
Code:
/**
* This function will simulate the getch() function from conio.h.
* Note that this does not work for special keys like F1-F12, arrow keys,
* even the ESC key does not seem to work with this function.
* @return TCHAR read from input buffer.
*/
TCHAR win_getch() {
DWORD mode;
TCHAR theChar = 0;
[code]....
View 2 Replies
View Related
Apr 3, 2013
I am having difficulty completing 7th last line below I marked the line with an arrow.
Code:
int main(void) {
int MaxNum, /*number of random nos to generate */
i, /*index */
value,
[Code].....
View 4 Replies
View Related
Jan 29, 2014
lets say we have a txt that contains this
| | | | |*| |
| | | |*| | |
and that symbolizes a 2x6 char array and we want to take only the symbols inside the || and place them in a 2x6 char array. how do we do that?
View 1 Replies
View Related
Jan 13, 2014
As a part of a program I am supposed to write, I would like to receive a string from the user (for example: "Hi my name is Joe").
obviously, the string is inserted to an array of chars (arr[0]='H', arr[1]='i', arr[2]=' ',... and so on).
What I would like to do, is to put each word separately in each array cell (for example arr[0]='Hi', arr[1]="my"..., and so on). How can I do this? (I can not use any functions, unless I write them myself).
View 8 Replies
View Related
Jan 7, 2014
How to give input with text for this function.i already create function for this but i dn't know give input as non ASCII value(0-32) that Cobain with string or simple text.
View 1 Replies
View Related
Nov 20, 2013
For some reason my code is not couting right. My function is supposed to decipher some code that if it has multiple same chars then it drops one. Example aabbyfkk --------> abyfk. But it couts abyffkk . For some reason it is not getting rid of the extra f and k chars.
string decrypt (string encrypted) {
string deleted, tmp;
int i, pos, n, j=0, z;
tmp=encrypted;
[Code] ....
View 3 Replies
View Related
Apr 2, 2014
I was supposed to sort out an input, getting rid of chars and only using the numbers. So 5a6g7we87hj9 would become 567879. I might be wrong in some way, but I used
if (scanf("%d", &n) {
printf(" %d", n);
}
else {
printf("Error);
}
and it sorted correctly.
View 1 Replies
View Related
Jan 16, 2014
I am receiving a max of 50000 bytes from a socket.
char packet1[50000];
recv(Socket, (char*)&packet1, 50000, 0);
What is the best way to read those bytes? Let's say I need to see if bytes 14-15 and byte 16-17 equal each other.
Only thing I can think of is to create a buffer array of 2 chars, and feed the bytes into those and compare them. Is that right?
View 5 Replies
View Related
Dec 9, 2013
I am trying to make a for loop that will print out chars in an array while using a #define before main. My problem is that each name has a different amount of chars in it. How do you account for that when you are trying to define a size? For example, I am playing around with the numbers and I just put 7 in for size:
Code:
#include <stdio.h>
#define sizeOf 7
//char personName( char * name[] );
char printName ( char * name[]);
[Code] .....
View 8 Replies
View Related
Nov 16, 2013
I'm trying to right the function that puts the correct letters in the right positons being reported from my previous compareletter function for my game of hang man and its not updating the word in progress array. Here's my compare letter function that's working correctly:
Code: //function that returns the index of the letter that the user has guessed or Code: //-1 if the letter isn't in the word
int CompareLetter(char array[], char guess, int numLetters)
{
int i;
[Code....
However, this isn't changing any of the position of the asterisks in the word in progress array positions 0-3.
View 7 Replies
View Related
Dec 14, 2013
That code should make the size of the pointer (how many chars it can store) bigger but when i run it it show always 3 char positions while it should show N*M.
Code:
#include <stdio.h>#include <stdlib.h>
int main(void) {
int M, N, P, i;
scanf ("%d %d", &M, &N);
P = M * N;
char *c = malloc(P * sizeof(char));
[Code] ....
View 7 Replies
View Related
Nov 28, 2014
Write a program that reads a group of chars till $. Then, compute # of vowels, # of digits, # of word and # of special chars. Your program should display all required results.
So in what way should I do it? Loop, array, ...?
View 13 Replies
View Related
Mar 29, 2014
current functions are:
char *createEnvironment(int width, int height, int numWoodChips);
void printEvrionment(char *environment, int width, int height);
need to be:
int* createEnvironment(int width, int height, int numWoodChips);
void printEvrionment(int* environment, int width, int height);
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
[Code]....
View 1 Replies
View Related
Feb 1, 2013
How do I detect garbage chars in a CString. Actually I'm reading some data from COM port. In some certain condition it will give some garbage as a version no. Now I need to show _T("N/A") in case of there is any garbage.
My solution is to check for a Valid char or integer. If found its correct else Garbage.
View 11 Replies
View Related
Jan 31, 2015
I'm supposed to create a program that will find the min/max values of two ints, doubles, and chars, It's not completely done but here's what I have so far.
It's giving me an Error 1 error LNK2019: unresolved external symbol "public: __thiscall MinMax<int>::MinMax<int>(int,int)" (??0?$MinMax@H@@QAE@HH@Z) referenced in function _mainC:UsersDerickDesktopCiss243Week3 Assignment2Week3 Assignment2Main.objWeek3 Assignment2
Header file
#ifndef MINMAX_H
#define MINMAX_H
#include <iostream>
using namespace std;
template <class T>
class MinMax
[Code] ....
I don't know why the site is adding in extra bits of code like /> in certain areas, it's not there when I paste it in and it's not in my code ....
View 5 Replies
View Related