C/C++ :: Cannot Get Strings To Print When Using For Loop

Mar 24, 2015

I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.

I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?

#include <stdio.h>
int main () {
/* variable definition: */

[Code].....

View 3 Replies


ADVERTISEMENT

C :: Can't Get Strings To Print When Using For Loop

Mar 6, 2015

I am making a program that takes the user's family names, their ages, and where they live. At the end I will be eventually averaging out their age and also printing the names of anyone who lives in Kansas.

I can't seem to get the Kansas part to work properly though.. When I execute the code, everything else works perfectly, but the Kansas part doesn't even print. Is there something different I need to do when strings are involved rather than integers/floats?

Code:

#include <stdio.h>
int main ()
{
/* variable definition: */

[Code].....

View 6 Replies View Related

C/C++ :: Print More Strings (the Strings May Contain Spaces)?

Feb 12, 2014

I have a problem who must print the sentences who have lenght more than 20 characters. I dont know why, but it prints just the first words. Look what i made.

#include<stdio.h>
#include<conio.h>  
int main()

[Code]....

For instance :

Give the number of sentences : 3

First sentence : I like the website bytes.com
Second sentence : I like more the website bytes.com
Third sentence : bytes.com

After I compile the program it should print the first two sentences.

View 2 Replies View Related

C++ :: Print Hexadecimal Strings From Binary

Aug 19, 2013

How to search in C or C++ a hexadecimal patterns within a binary file.

For example:

String1:

Code: 0x44 0x65 0x07

Then, once found, extract those 3 bytes and the next 11 bytes (14 bytes in total).

Finally, from those 14 bytes, print without spaces "bytes 1 to 6", "bytes 6 to 12", and byte "13 to 14".

Then I would like to print last 2 bytes (13 to 14) joined in decimal format.

The output without any conversion would be:

Code:
446507c90688 888000800005 0015
4465072ec918 059173495269 002C
44650700cc01 01811bc90b00 00AB

But the output converting to decimal the last 2 bytes would be:

Code:
446507c90688 888000800005 21
4465072ec918 059173495269 44
44650700cc01 01811bc90b00 171

The sample file is attached, and looks like this:

Code:

06 00 00 80 00 00 00 80 09 3c c9 06 88 88 80 00
80 00 44 65 07 c9 06 88 88 80 00 80 00 05 00 15
37 06 01 00 00 01 00 65 00 00 00 02 00 00 02 00
18 00 00 00 03 00 00 03 00 17 00 00 00 04 00 00

[Code] .....

View 8 Replies View Related

C :: Compare 2 Strings And Print Out 1 If Characters Match And 0 If Not

Oct 29, 2014

This program is supposed to compare 2 strings and print out a 1 if the characters match and a 0 if they dont. It compiles but doesnt give me the correct output.

Code:
#include <stdio.h>
#include <string.h>
void func();
int main () {
func();
return 0;

[Code] ....

View 11 Replies View Related

C++ :: Mapping Strings To Integers - How To Print String Zero

Dec 12, 2013

I'm very very new to maps and am really just trying to hash them out by myself.

If you're mapping strings to integers:

map <string, int> myMap;
myMap[ "zero" ] = 0;
myMap[ "one" ] = 1;

How do I print the string "zero", for instance, from myMap?

cout << myMap.at(0) << endl;

doesn't work. Nor does:

cout << static_cast<string>( myMap.at(0) ) << endl;

I need access to the string using the int and the int using the string. Or just direct access to one or the other. . . It's just confusing that they're technically mapped to one another but I can't really access either of them.

View 4 Replies View Related

C/C++ :: Print Array Of Strings Is Printing Null Instead Of Result

Feb 17, 2014

I am trying to print the array of string using this code but the compiler is printing null in the output:

The code is as follows:

char *arr[10];
int i;
for(i=0;i<10;i++)
scanf("%s",*(arr+i));  
for(i=0;i<10;i++)
printf("%s
",*(arr+i));

View 3 Replies View Related

C++ :: Testing HTTP Headers - For Loop And Strings

Jun 23, 2014

I am testing HTTP Headers and I have an strange problem. When I get the response of the server, it is the correct one the first time. If I use a for loop to send more than one request and get more than one response, this response seems to be overlapped with the previous ones. To a better explanation of the problem I attach the code I am using and the output generated:

TCPSocket.h
-----------
#ifndef _TCPSOCKET_H_
#define _TCPSOCKET_H_
class TCPSocket {
private:
int localSocket;

[Code] .....

So, a bigger loop, a bigger the response of the server. However, I know the response of the server is always the same.

View 3 Replies View Related

C/C++ :: Loop To Add Ints / Strings Into Vector In Ascending Order

Feb 24, 2014

The code is supposed to take either an int or a string (and their respective vectors) and insert a given int or string into the vector in ascending order. My code works properly for ints, but it's having a problem with strings.

The order I get with the strings given is

penguin
banana
great
jungle

For some reason comparing penguin to banana/great doesn't give the expected result. The template attached only includes the function and the private vectors needed for the function.

template<class T>
class orderedList {
public:
void insert(const T& item);
private:
vector<T> list;
int total = 0;

[Code] ....

View 11 Replies View Related

C/C++ :: Why Does Printf Not Print After A While Or For Loop

Jul 1, 2012

I would like the following code to print: "Why doesn't this print?" and "I would like to print the sum of nc: 5". What am I doing wrong.

#include <stdio.h>  
//Use to test ideas and formats//  
main() {
    int c, nc;      
    nc = 0;  

[code]....

My result as compiled by gcc -o testing testing.c

This prints.

test
t1,e2,s3,t4,
5,

I have not figured out how to sum and print as the above code indicates, which complicates my ability to do many of the exercises in "The C Programming Language". I am using a MacBook gcc compiler and X code as well. I cannot get the last two printf functions to work. I did the temperature example with "while (fahr <= upper)" and the printf printed.

View 7 Replies View Related

C/C++ :: Print Series Of Text From Loop

Sep 29, 2014

I'm attempting to print a series of text from this loop, but for some reason all I am getting is the sum total and the number 1, like this

1 5175.11

When I want to get it for each iteration of the loop. I've cycled over this and compared it to my other loops I've used and I'm lost as to why this isn't working. I also tried using a do while but that didn't work as well.

for (double total1 = 0; total1 < goal; total1 + save_amt) {
total2 = ((factor - one) * save_amt);
total3 = (total2 / fr_interest);
total1 = total1 + total3;
months_dis = (months_dis + one);
cout << months_dis << " " << total1 << endl;
}

View 14 Replies View Related

C :: Print Triangle Pattern Using One Loop And Recursion?

Dec 18, 2013

Q.print triangle pattern using one loop and recursion

eg: 5

Code:

#include <stdio.h>#include <conio.h>
void pattern(int n,int N) {
int i,c=1;

[Code]....

View 8 Replies View Related

C/C++ :: Print 10101 And 01010 Series Using For Loop

Apr 11, 2014

10101
01010
10101
01010

I want print above series using for loop.

View 2 Replies View Related

C++ :: Print ASCII Characters - Limit In For Loop

May 1, 2015

#include<iostream>
#include<conio.h>
using namespace std;
int main(void){
clrscr();

[Code] ....

I am trying to print ascii characters but problem is If i put a limit in for loop to 255 or more than 126 the output don't stop it keeps on going

I know there is another way to this program but what i want to know this why this happen in this logic....it doesn't happen if a<=125 or less then 125.

View 7 Replies View Related

C++ :: Count Controlled Loop Than Can Print Char

Sep 27, 2012

Write a count controlled loop than can print "i" char. The user is supposed to input a integer and that integer is how many asterisks there is on the blade, in this case it is 5.

* *
** ** **---------------
*******
** ** **
* ** * -10 Rows high
** -blade always connects on second row of handle
**
**
**
**------------------

These are the steps he told us to do it in.

1) *
**
***
****
*****

2) *
**
***
****
*****
****
***
**
*

3) * *
** **
*** ***
**** ****
**********

4) * *
** **
*** ***
**** ****
**********
**** ****
*** ***
** **
* *

5)* *
** ** **
*******
** ** **
* ** *
**
**
**
**
**

View 4 Replies View Related

C++ ::  Vertical Histogram - Variables In For Loop To Print Stars

Dec 6, 2013

I want to create a vertical histogram in my code. I already made it go vertical but not the way I want it.

Example:
I want it like this:

Range1 Range2 Range3 Range4

And asterisks under each one, depending on the user input. (My code is below and doing it on here doesn't make it come out correctly)

But what I've managed to do is this:

Range1
*
*
*

Range2
*
*

Range3
*
*
*
*

Range4
*
*

Which I don't want. I want everything else to stay pretty much the same since I can only use some features such as Arrays and really basic functions.

Here is my code: (Worked fine last time I used it and I am doing it on Visual Studio 2010 (at uni) and 2013 (on my laptop)).

#include <iostream> //Start of code
using namespace std;
int MarkValueInput; //Mark entered by user
//Counter variables for ranges in While Loop
int counterlow; //Counter for low range
int countermidlow; //Counter for mid-low range
int countermidhigh; //Counter for mid-high range
int counterhigh; //Counter for high range

[Code] .....

View 4 Replies View Related

C/C++ :: For Loop To Print Given Character Number Of Times Specified By Integer

Feb 11, 2014

The function uses a "for" loop to print the given character the number of times specified by the integer.

How can I make a for loop to do that?

So.. my code looks like this:

// cpp : Defines the entry point for the console application
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void printMyInteger(int myInteger, char myChar) {

[Code] ....

So.. here is my error:

Error1error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
Error2error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
3IntelliSense: expected an expressiond:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp107Week 6

View 3 Replies View Related

C# :: Infinite Loop Random Boolean Print Statement

Feb 19, 2014

I am working on a small simple program my program fills up a air plane with customers there is 2 levels 1 and 2 and it will put that person in the spot depending on being picked.

So far i made a boolean airplane with 10 spots I can enter 1 person into the airplane with no problem but then after he sits down i get a infinite loop? I assume i maybe have to use the continue statement I feel like there is something simple that im missing i want to add more people. here is what i have

class Program
{
static void Main(string[] args)
{ bool[] planeSeats = {false, false, false, false, false, false, false, false, false, false };

[Code]......

View 1 Replies View Related

C++ :: Print Each Percent Of Loop Breaks Down For Large Loops?

Feb 22, 2012

I'm trying to make a percentage counter inside a loop, printing each completed percent of the loop as it goes. I've managed to write such code, but when I run it the percentage output breaks down (becomes negative!) for large loops. I have an example below.

Code:
#include <iostream>
#include <sstream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
using namespace std ;
int main() {

[code].....

Compiling and running the above yields the output:

Code:

...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...-21% ...-20% ...-19% ...-18% ...-17% ...-16% ...-15% ...-14% ...-13% ...-12% ...-11% ...-10% ...-9% ...-8% ...-7% ...-6% ...-5% ...-4% ...-3% ...-2% ...-1% ...0% ...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...-21% ...-20% ...-19% ...-18% ...-17% ...-16% ...-15% ...-14% ...-13% ...-12% ...-11% ...-10% ...-9% ...-8% ...-7% ...-6% ...-5% ...-4% ...-3% ...-2% ...-1% ...0% ...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14%...100%

If I change the value of N to 1e7 instead of 1e8, the output is correct however!

Code:
...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...22% ...23% ...24% ...25% ...26% ...27% ...28% ...29% ...30% ...31% ...32% ...33% ...34% ...35% ...36% ...37% ...38% ...39% ...40% ...41% ...42% ...43% ...44% ...45% ...46% ...47% ...48% ...49% ...50% ...51% ...52% ...53% ...54% ...55% ...56% ...57% ...58% ...59% ...60% ...61% ...62% ...63% ...64% ...65% ...66% ...67% ...68% ...69% ...70% ...71% ...72% ...73% ...74% ...75% ...76% ...77% ...78% ...79% ...80% ...81% ...82% ...83% ...84% ...85% ...86% ...87% ...88% ...89% ...90% ...91% ...92% ...93% ...94% ...95% ...96% ...97% ...98% ...99%...100%

View 5 Replies View Related

C++ :: Print In Asterisks Oval / Arrow And Diamond Using For Loop And If Statements

Jan 15, 2015

#include <iostream>
using namespace std;
int main(){
return 0;
}

this is my main functions. I have problem making a program that prints in asterisks an oval, arrow and a diamond using for loop and if statements.

View 1 Replies View Related

Visual C++ :: Use For Loop To Read Certain Data From Txt File And Print To Console

Sep 28, 2014

I'm new to programming and i'm trying to do a certain task. I want to use a for loop to read certain data from a txt file and print them to a console. I'm trying to read student names and their grades.

Something like
3 // 3 represents the number of students.
George 97
Sarah 70
Maya 88

The data may vary but it's always in this format.

View 14 Replies View Related

C :: Loop Statement To Print Numbers From 1 To 10 In Reverse Order Separated By Star

Apr 21, 2013

Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :

10*9*8*7*6*5*4*3*2*1

i try to do it but it show me like this :

10*9*8*7*6*5*4*3*2*1*

how do i write to show me like the first one ?

View 10 Replies View Related

C :: How To Print Strings On The Same Line Without Moving To Next Line

Mar 12, 2013

Just working up for the google coding contest to start soon and have been practising some of the test questions however i make correct algorithms but my output is rejected because of the fact that my strings are printed on a new line so i wish to know a method to print strings using a printf statement or any other function on the same line ...

View 3 Replies View Related

C :: ANSI Program To Print Out Each Command Line Argument On Separate Line Using For Loop

Mar 5, 2013

I need to write a ANSI program to print out each command line argument on a separate line using a for-loop. also it need to print the name of the executable .so far I have

Code:

#include <stdio.h>
int main(int argc, char **argv) {
int i;
printf("")

[code]....

View 1 Replies View Related

C++ :: How To Append Strings To The Front Of Other Strings

Apr 7, 2013

I am programming a translator, and I have it so that it detects words with spaces both in front of and behind them, so I did "string.append(space);" where space equals " ". That added a space to the end, but I still need a space added to the front.

View 1 Replies View Related

C :: Won't Print Numbers Sorted When Use Print Function

Nov 17, 2013

I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort

Code:

void Sort(int ary[], int size)
{
int temp;
int smallest;
int current;
int move;
}

[code]....

put it wont print the numbers sorted when I use my print function, just the unsorted numbers.

View 1 Replies View Related







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