C :: Printing A Char String From A Struct

Jan 3, 2015

I am trying to save 5 persons names to a struct, and then printing them afterwards, shortly before the program ends. I tried to print the char string out right after it has been copied over, and it showed fine, but when i try to write it out right at the end of the program (its in a separate function) the terminal just prints gibberish.

the function looks like this:

Code:
int printUser(){
printf("Following patients have been recorded in this session:
");
struct database patient1;
struct database patient2;
struct database patient3;

[Code]...

the output looks like this(as you can se in under structest, that it shows the correct string, it also uses printf):

View 7 Replies


ADVERTISEMENT

C :: Printing A String On A Char Matrix

May 27, 2014

So I have an array of char called s.This array has many words inside, each one separated by ''.The words are sorted by length (from bigger to smaller).I have have a char matrix with random things inside (it was not initialized) caled mat.I want to copy the first word from the array s to the matrix mat.

Code:

int nlin, ncol; /*number of lines and collumns.*/
int c,l,a,q;
char mat [1000][1000];
char s[1000];
}

[code]....

I can't see where this is wrong, but, when i test it, it clearly is not right. for example, if the input is 3 lines and 3 columns for the matrix and the word is crate, the output is :

cra
t
e

but it should be:

cra
t
e

View 11 Replies View Related

C++ :: Assign String To Char Array Of Struct

May 6, 2013

#include <iostream>
using namespace std;
struct box{

[Code].....

C++Dev.cpp:23: error: incompatible types in assignment of ‘const char [15]’ to ‘char [40]’

View 2 Replies View Related

C/C++ :: Printing Struct Array After Inputting Information?

Aug 28, 2014

I am doing a data structures program on C++ that is suposse to consist of declaring an array of size five for my credit card structure, that allows the user to input information of five diferent credit cards. I am having a problem with my program, because it runs but after I input the information of the credit card, it does not print out the values that I had input.I dont know where I went wrong with the code or if it is that my approach to solving it is wrong. My code is the following:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct TarjetaCredito

[code].....

View 2 Replies View Related

C++ :: Using Struct / Char Array For Tic Tac Toe Game

Feb 11, 2014

I basically just want a function that tells me if 'X' or 'O' won in a tic-tac-toe game. I don't care about the visuals, I just want a function that tells me if 'X' or 'O' won. If X wins, return 0. If Y wins, return 1.

How to do the diagonals, but as far as the across and down wins, I know I have to use a nested for loop, but am a little stuck, as to exactly how to set it up.

#include <iostream>
using namespace std;
struct TTT{
char array[3][3];
unsigned moves;

[Code] ....

View 1 Replies View Related

C++ :: Error On Assigning New Char Value From Struct

Feb 17, 2015

Well I tried to assign a new char value from a struct to another char variable but I got the "Cannot convert 'int' to 'char'" error when compiling. I've tried several alternations but I still can't get away with this error.

Here's a section of the code:

javascript:tx('code')
for(int i = 0 ; i < 10 ; i++){
pts[i].dist = sqrt((pts[i].x*pts[i].x)+(pts[i].y*pts[i].y));
}

[Code].....

View 1 Replies View Related

C/C++ :: Ordering Element (char) In A Struct

Dec 9, 2014

what is the function of ordering element(char)in a struct

View 1 Replies View Related

C++ :: Initialize Char Pointer Array In Struct

Nov 28, 2014

I am trying to store data in a struct to be able to read it latter . have problems initializing this.

struct FoodAndDrink {
struct Food {
char* CannedGoods[2] = {
"Canned Spaghetti",
"Canned Tuna",

[code] .....

View 7 Replies View Related

C :: Appcrash Segmentation Fault Char Inside Struct

Apr 24, 2013

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

typedef struct info info;

[Code] ....

View 2 Replies View Related

C++ :: Printing A String To A File?

Aug 24, 2013

these are the errors that I'm getting from an online c++ compiler

// main.cpp:4:10: error: #include expects "FILENAME" or
// main.cpp: In function 'void permute(char*, int)':
// main.cpp:17:9: error: 'f' was not declared in this scope

I don't understand how to print full_string to a file!// otherwise, I know that it gives the correct output -- 90 strings.

#include <string>
#include <iostream>
#include <fstream>
#include >ios> // line 4 error
using namespace std;
char full_string[] = "112233";

[code]....

//iter_swap – it just swaps the elements pointed to by the respective pointers without changing the pointers themselves. so, it's basically equivalent to the function:

void iter_swap(char *ptr1, char *ptr2) {
char tmp = *ptr1; *ptr1 = *ptr2;
*ptr2 = tmp;
}

// min_element – finds the location of the minimum element that exists in the given range. in this case,

it is the char* pointer pointing to the location of that element. it can be implemented like:

char *min_element(char *start, char *end) {
// end is 1 beyond the last valid element
if(start == end) return end; // empty range
char *min_pos = start;
for(char *iter = start+1; iter != end; ++iter)

[code]....

View 7 Replies View Related

C++ :: Printing Each Element Of Whole String

Dec 26, 2013

Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string s="Last Assignment/n";
cout<<j[1]<<j[2]<<j[3];

I don't understand how it printing each element of whole string. Like L a s. But I did not declared array.

View 2 Replies View Related

C++ :: Printing Substrings From Input String

May 24, 2014

I'm having trouble printing the text in between separators like commas, periods, and at signs. I'm following Jumping into C++ Chapter 19 Practice Problem 2.

This is what I have so far:

Code:
#include <iostream>#include <string>
usingnamespacestd;
int findNeedle (char separator, string inputLine) {
int needleAppearences = 0;

[Code] ....

And this was my test run output:

Enter the contact info. one, two, three, ,? , one two, th three, Program ended with exit code: 0

View 4 Replies View Related

C :: Printing All Combinations Of A String Loop

Jan 25, 2013

Code:

#include<stdio.h>
#include<string.h>
#define a 15

[Code]....

I am trying to print all combinations of a string but I couldn't figure out how to do loop for it. Code works only 2-3-4 letters words

View 4 Replies View Related

C++ :: Program For Printing All The Combinations Of A String

Feb 17, 2013

I am trying to write a program for printing all the combinations of a string. Why this program is giving the error message.

"First-chance exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4..
Unhandled exception at 0x761bc41f in word.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0026f6b4.." when i try to run this in MVS 2010

#include<iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<conio.h>
void combination(std::string input,int length,std::string buffer,int allowedno)

[Code] .....

View 1 Replies View Related

C++ :: Printing String In Reverse Order

May 14, 2014

How to print a string in reverse order(for example: "today is Wednesday " to "Wednesday is today"). My professor said we should begin with a null string and build it one word at a time.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int nwords(string);

[Code] .....

View 1 Replies View Related

C/C++ :: Finding And Printing A Substring In A String?

Feb 21, 2015

i couldnt solve the algorithm exactly. The program asks the user for a string. "Bugun h@v@ cok g'uzel" for example. then the program asks for another string. If that string doesnt exists in the main string program should say there isnt any substring. If it exist then the program should print the remaining part of main string. For example:

Write the first string: Tod@y weather is be'@utiful
write the substring : ug
>>ugun h@v@ cok guzel
write the substring :wldnqwbdbj
>>there isnt any substring
Here where i came so far

#include <stdio.h>
int main()
{
char mainstr[50],substr[50];

[Code]....

View 7 Replies View Related

C/C++ :: Printing A Map That Contains A String And A Class With Integers?

Dec 14, 2014

I'm new to c++, so how to print the contents of a map that contains a string and a class of integers for option 1. what formatting should I use?

#include <iomanip>
#include <vector>
#include <sstream>
#include <map>
#include "IPHost.h"
#include "EncryptedConnection.h"

[Code] .....

View 6 Replies View Related

C :: Printing String Yields Strange Output

Feb 23, 2015

I'm reading in a string from the command line into a char array followed by a series of ints which are read into an int array.

The command line

Code: lab3 word word word 0 0 2 3 results in the following output:

Code: Word: .N=▒
Number of Words: 0
Word: .N=▒word word word
Number of Words: 3
Num: 0
Num: 0
Num: 2
Num: 3

Here is the source code:

int main(int argc, char *argv[]){
if(argc < 2){
//command line must have at least three arguments (one
//char, one integer)
printf("Error: invalid number of arguments

[Code] .....

Where is the .N=▒ coming from?

View 3 Replies View Related

C++ :: Printing Contents Of A String That Also Exist In A Vector

Jan 27, 2014

For the last part of this problem, if player 2 loses the game of hangman, I need to display the letters they did get right. In order to do that, I believe that I need to traverse vector v for the elements that exist in the string hiddenword, and then print those characters that match.

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int letterFill (char, string, string&);

[Code] ....

View 1 Replies View Related

C++ :: Count String In A String Using Datatype Char

Dec 20, 2014

I have the codes for such a problem where, to create a program that counts how many times the second string appears on the first string. Yes it counts if you put 1 letter only, but if you put 2, it is an error. As an example. If the first string is Harry Partear, and the second string is ar, it must count as 3. Here's the code:

Code:

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

[Code] ....

View 6 Replies View Related

C++ :: Char Array To String - String Becomes Garbage

Apr 20, 2013

I'm trying to "tokenize" a string using std::string functions, but I stored the text in a char array. When I try to convert it to a string, the string has the first character right but the rest is garbage.

// Get value from ListBox.
char selectedValue[256];
memset(selectedValue, NULL, 256);
SendMessage(GetDlgItem(hWnd, IDC_LB_CURRENTSCRIPT), LB_GETTEXT, selectedIndex, (LPARAM)selectedValue);
// Convert to string.
string val(selectedValue);

[Code] ....

View 3 Replies View Related

C++ :: String Class That Finds A Char In String?

Feb 5, 2013

A string class that finds a char in the string?

View 1 Replies View Related

C :: Save Values From A Char Buffer Into Integer Values Of A Struct?

Jul 3, 2013

I'm attempting to save values from a char buffer into integer values of a struct.

This is what resides in the buffer "STD 2 2 2 2 2 2 2 " and this is my sscanf call

Code:
sscanf(buffer, "STD %d %d %d %d %d %d %d
", &dt_struct.date,
&dt_struct.mth,
&dt_struct.year,
&dt_struct.dow,
&dt_struct.hr,
&dt_struct.min,
&dt_struct.sec);

I then print the values back out in a string using sprintf.

Code:
sprintf(t_string, "STD %d %d %d %d %d %d %d
", dt_struct.date,
dt_struct.mth,
dt_struct.year,
dt_struct.dow,
dt_struct.hr,
dt_struct.min,
dt_struct.sec);

But this is what I get:
STD 0 0 2 0 0 0 2

Instead of what I want:
STD 2 2 2 2 2 2 2

View 7 Replies View Related

C :: Parsing Char Array To Array Of Struct To Process Packets

May 28, 2013

I wrote this simplified version of a program i am writing that parses data in UDP packets. In the process of doing so i pretty much answered all my questions and fix all the problems i was having.

decodeSystemMap function will be in loop, and will proccess packets that have mostly the same data, only a few items will be added or changed or deleted.

whats the best way to check if there are any new, deleted, or removed items in the packet and only modify those?
Is there anything unsafe / dangrous about the way the code is now?

Code:
/* * File: main.c
* Author: david
*
* Created on May 23, 2013, 11:57 AM
*/

#include <stdio.h>
#include <stdlib.h>

[Code] ....

View 4 Replies View Related

C++ :: Searching String Within Vector Struct

Nov 3, 2013

New to C++ lambda, got two question in regards of searching for strings within a vector struct.

Minimalistic example:
Code:
struct singleFile {
std::string filename;
};

std::vector<singleFile>myStorage;
myStorage.push_back(singleFile());

[Code] ....

1) why does found always return 0 eventhough the filename exists?

2) I don't know how to pass an actual search string instead of the hardcoded approach as above with filename =="

View 6 Replies View Related

C :: Splitting String And Copying It Over To A Struct

Sep 26, 2013

I'm having trouble with this code. What I'm trying to do is to read a line from a file and cut that line into two pieces, one is the keyword and the other is the definition. I want to read up to when there is a dash and assign that line to key and then assign the rest of the line to def. After that I copy key to the struct DictEntries.key and def to DictEntries.def. The output of this shows only the definition for both DictEntries.key and DictEntries.def but if I use "puts(key);" I see the keyword.

Code:

while(!feof(dictionary))
{
char line[200];
char *key,*def;
fgets(line,sizeof(line),dictionary);
key = strtok(line,"-");
}

[code]....

View 12 Replies View Related







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