C++ :: Char - Adding ABCs (letters)?
Mar 12, 2014
How I can go back to an alphabet letter I want that letter to land on? Adding capital letters. Lower case letters not needed.
For example;
- User enters "XYZ"
- Program comes up with the next 10 letters which would be something like 'HIJ' (Since X+10 = H, Y+10 = I, Z+10=J)
My problem is with the last few letters. The program goes to the next 10 characters ahead of those characters rather then the alphabet.
Program example: (What I want shown)
"What are your three favorite letters?" XYZ
"The next ten letters are: HIJ"
Error example: {It goes to the next 10 characters instead of the next 10 alphabet letters.)
"What are your three favorite letters?" XYZ
"The next ten letters are: ^[a"
Code example: (I've tried other ways as well.)
char a, b, c;
cout << "What are your three favorite letters?";
cin >> a >> b >> c;
cout << "The next ten letters are: " << a+10 << b+10 << c+10 << endl;
View 4 Replies
ADVERTISEMENT
Dec 7, 2014
Assume input is char array holding a C-string. Write code that counts the number of elements in the array that contain an alphabetic character.
counter = 0
for (i = 0; i < SIZE; i++) //size being whatever input's size is
{
if (isalpha(input[i]))
{
counter++;
}
}
Is there anything wrong with this method?
View 8 Replies
View Related
Dec 30, 2013
The book uses this example:
#define ALLOCSIZE 10000 /* size of available space */
static char allocbuf[ALLOCSIZE]; /* storage for alloc */
static char *allocp = allocbuf; /* next free position */
char *alloc(int n)
/* return pointer to n characters */
[Code] ....
The logic here I don't understand:
if (allocbuf + ALLOCSIZE - allocp >= n)
allocbuf is a char array allocated with 10000 positions. We add that to ALLOCSIZE macro which is 10000. Does that return a value of 20000? If so, it doesn't make sense to do this because all we had to do was this:
if (allocbuf - allocp >= n)
That takes length of allocbuf which is 10000 and subtracts allocp from it. So if allocp is 1000 we are left with 9000 available slots. And we can use that to check if we have enough to allocate n elements.
View 5 Replies
View Related
Aug 15, 2014
I am making a program that formats a string. I want to create a new 2 dimensional string that will have many other chars and strings in it beside the original string. Then I split the string up on the newlines and return it. Adding different parts to the 2d string e.g. I need to add five _ as chars not string then I need to add different things. First I use sprintf () to add as much as possible. And then I do what to add the rest?
View 13 Replies
View Related
Oct 29, 2014
Code:
cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())
[Code] .....
View 8 Replies
View Related
Dec 23, 2014
I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.
this is the entire code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
[Code]....
at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.
View 4 Replies
View Related
Sep 29, 2014
I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.
/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit
[Code]....
View 2 Replies
View Related
Mar 16, 2013
I'm just trying to find out if the way I've setup my code currently allows me to count the letters as they occur? I don't yet see how to do it but I need clarification. Ideally the function letterCounter would do the counting but atm I'm just trying to figuring it out in the display function.
View 2 Replies
View Related
Nov 28, 2013
I need to do a function that copy every word from a text to a char word. How can i do it?
View 5 Replies
View Related
Jan 26, 2013
Code:
#include<stdio.h>
#include<string.h>
#define a 9
#define b 9
#define c 3
int main() {
[Code] .....
In practice section there was a challenge to print up numbers in letters up to billion including negatives I didn't look at the solution and came up with this but it is getting difficult after this point....
View 9 Replies
View Related
Nov 14, 2013
These are the instructions: read a number between 1-26 and build a parallelogram in the size (height&width) of the number entered.
Each row of the parallelogram will be built from each capital letter from 1 to the number read (max 26).for example: by entering the number 3, will be printed:
AAA
_BBB
__CCC
for the number 4:
AAAA
_BBBB
__CCCC
___DDDD
I am struggling with how to change each char in every different row, how do I print this parallelogram ?
View 8 Replies
View Related
Jun 3, 2014
i m trying to write a code that would convert a each letter from a text to their decimal images . while i was able to write the part of entering the text , i cant do the converting part , i searched all day on the internet and found nothing.
View 3 Replies
View Related
Jun 1, 2013
I have a text file in which i need to read only selected letters and substitute them with integers to calculate.
Eg:-
In the text file
f2,h1
Here i need to read only the the letters f & h and substitute them with some integer and add them up.
View 1 Replies
View Related
Nov 28, 2013
I need help writing a program where I use small letter to write names in Big letters. (I dont know if you understand what i mean). Follow link to description.
[URL]
View 6 Replies
View Related
May 3, 2013
I have a function that is suppose to swap positions of 2 letters but It doesn't seem to work. Im passing in the array of char into the function.
void swapletter(char word[]) {
char temp1;
int swap1;
int swap2;
cout<<"What is the first location: ";
cin>>swap1;
[Code] ....
View 6 Replies
View Related
Mar 11, 2013
how to put 2 letters together and make them to count as 1?
provided that they must consecutive
for example:
p : count as 0
pxp : count as 0
pp : count as 1
xpxp: count as 0
ppxpp : count as 2
View 1 Replies
View Related
Sep 26, 2013
I am writing a code that requires the user to input either B or b for bright or D or d for dim. Basically, B is bright and D is dim but I have to code the program such that it allows for both he capital letter and the lowercase letter to be recognized.
View 1 Replies
View Related
Aug 13, 2014
i'm trying to replace letters in a word...here's the code so far
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main (){
string s;
[Code] ...
The problem is if i type "nm" i'm not getting "mn" as the output, it's "mm"
I'm not trying to swap letters between them
View 1 Replies
View Related
Mar 20, 2014
Just wrote this extremely simple program but it seems to be malfunctioning. It counts correctly the number of uppercase letters in a string so long as i don't use the space-bar. once I add a space it only counts the number of uppercase letters of the first word..
printf("I ..........ing love programming");
Code:
#include <stdio.h>
main()
{
char text[200];
int i = 0;
int uppercase = 0;
printf("Enter text:");
scanf("%s", text);
[code]....
View 6 Replies
View Related
Feb 11, 2014
I have to develop script in C to print the alphabets in given notation.
Please check the attachment.
View 4 Replies
View Related
Oct 15, 2013
Im still new to this but i dont quite understand whats wrong with this code
Code:
#include <stdio.h>
int num1, num2, num3;
char resp;
int main()
{
printf("Quer os seus numeros em ordem crescente ou decrescente?
[Code] ....
It is in portuguese but the thing is, when i type the C when it asks for the response it still reads as if it was D the response
View 5 Replies
View Related
Mar 6, 2015
I'm doing error checks in C and I'd like to know how to restrict the input of a string to 2 letters and if it is exceeded, i'd like to loop and ask for the code to be re-entered.
Code:
for (i = 0; i < code7; i++)
{
printf("Enter number of items: ");
scanf("%d", &item_qty[i]);
[Code].....
View 2 Replies
View Related
May 5, 2014
I am creating a program where I count all the letters of the alphabet from a user submitted string.
How would I go about this?
I am completely new, so simplicity is best. I am suppose to use arrays.
View 4 Replies
View Related
Dec 25, 2014
Okay, so I have a science fair project and I decided on doing a series of programs that show the simpleness behind hacking a password. Each program increases in complexity starting with a four digit password, and ending with a 10 digit letter and number combo that is case sensitive. Right now I need to figure out a way to have my program be able to convert chars into ints, so that I can do a counter and then I also need to be able to convert the ints, back into chars.
View 19 Replies
View Related
May 12, 2014
I am trying to write a program to get user's input but only accepts alphabetic characters, nothing else and I want it to ask the user to enter a valid word until they have finally entered a valid one. I have the following code for it but it does not work properly.
void CheckBound (char word1[], int SIZE1) {
int i;
int w1[SIZE4]= {0};
int found;
for (i=0;i<strlen(word1);i++) {
[Code] .....
View 2 Replies
View Related
Feb 27, 2014
I am trying to make a program into which you writre for example ten Names or words or etc. and it would find the longest name/word write it and the numbers of characters too but I have problem with displaying that name. Here is me source code, the problem is here "vitaz=szInput;" i don't know how to save that longest name/word.
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
int main () {
char a;
char szInput[256],vitaz[256];
[Code] .....
View 5 Replies
View Related