C/C++ :: Printf Several Values Of Struct Pointer?
Jan 14, 2015
I am currently trying to printf several values of a struct pointer but with little success.
#include"Header.h"
/*
In header:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
struct FileStruct {
char FileQuestion[64];
[Code] ....
As you can see I am trying to re-crate the output from the first loop in my second loop, however it is with little success. The second loop's first run re-crates the last output of the first loop and if I use FileStructPointer++ or -- the output goes broke.
See attached for how it looks in the console window.
Attached image(s)
View 3 Replies
ADVERTISEMENT
Apr 22, 2014
Code:
#include <stdio.h>
struct database {
int id_number;
int age;
float salary;
[Code] ....
When I compile, I get an error:
test.c|18|error: incompatible type for argument 1 of 'printf'|
note: expected 'const char *' but argument is of type 'float'|
I thought employee.salary is a float but the compiler expected 'const char'. How do I make this work?
View 4 Replies
View Related
Jun 5, 2012
"
#include <stdio.h>
struct datastructure {
char character;
};
void function(struct datastructure** ptr);
[Code] ....
These codes give these errors:
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
These errors are related to
"
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
"
I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.
View 3 Replies
View Related
Apr 18, 2014
I cannot get the following to compile. The problem is the printf on the last line. I understand that printf requires a char (or pointer to char). I understand that I can convert between datatypes by putting the target data type in parenthises in front of the variable. But how do I cast the integer into a character and then get it's pointer to pass into printf?
Following is my code. I compile with gcc temp.c -o temp.
Note that I have tried many attempts at that last line and this is just the one that I really, really think should work (or is at least the closest to the correct answer).
This code shown below, using printf("%s", &(char)nextChar); returns
temp.c:26: error: lvalue required as unary '&' operand
If I try to use printf("%s", *(char)nextChar); I get the error
temp.c:26: error: invalid type argument of 'unary *' (have 'int')
This line printf("%s", (char)nextChar); returns the obvious
format '%s' expects type 'char *', but argument 2 has type 'int'
Code:
#include <stdio.h>
int main() {
printf("hello, world
");
#if defined(SUNDIALS_EXTENDED_PRECISION)
[Code] ....
View 5 Replies
View Related
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
Mar 6, 2015
how can I call and print the Pointer:
ptr->address
Code: #include<stdio.h>
struct account {
int address;
int value;
[code]....
View 5 Replies
View Related
Nov 6, 2014
I want to count values in a struct.
typedef struct {
int x;
int test;
}TYPE_TEST;
TYPE_TEST My[6] ={
{16, 50},
{4, 51},
{50, 52},
{47, 53},
{10, 54},
{19, 55}
};
int Newbuffer[ ????? ]
Now I want to make the size of Newbuffer the sum of all "x", that is 146. Not the size of X.
But how to sum all "x".
View 5 Replies
View Related
Feb 13, 2015
I'm a C beginner trying to assign struct member values to other struct members to create a list.
I've tried dot notation, pointer notation, strcpy, memcpy, memmove and normal assignment.
Nothing has worked.
cust_list.h
View 5 Replies
View Related
Apr 5, 2013
I'm trying to print values from a vector of a struct and I don't really know how to do that. Here is a simple code that I have for now to test how to add data to the vector then attempt to print it out.
#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <fstream>
using namespace std;
struct Employee//employee data
[Code]...
View 2 Replies
View Related
Mar 9, 2015
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
struct stock{
char symbol[5];
int quantity;
float price;
[Code] ....
- In the final output
Value
%.2f
- How is the final pointer reference at line33 leading to the output %.2f ? (i do understand that the %% is used to display a %] ....
View 1 Replies
View Related
Aug 25, 2014
I want to have a function pointer inside a typedef struct but I get a segmentation fault when I run my code. Here's my code:
#include <stdio.h>
typedef struct Foo {
void (*bar)(int);
} Foo;
void func(int x) {
printf("display: %d
[Code] ....
View 2 Replies
View Related
Jul 19, 2014
I am using a struct and tying to send values to it as byte value
Code:
#include<stdio.h>
typedef struct{
unsigned r1:1;
unsigned r2:1;
unsigned r3:1;
[Code] ....
Error: invalid suffix "b00100000" or incompatible types in assignment
I am able to access the member as Range.r1 = 1; and have no problems. I want to send data whole at once, but how ?
View 8 Replies
View Related
Nov 23, 2013
This is a c++ Code. I want to read a address to a pointer. When I try to do so it generates an error. I did is >> obj1[0].contentAdress; in main.
struct node3{
node3(){
nextContent = NULL;
for (int i = 0; i<1020; i++)
content[i] = '';
[code]...
no operator found which takes a right-hand operand of type 'node3 *' (or there is no acceptable conversion)
View 12 Replies
View Related
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
Mar 17, 2013
i need to return a struct pointer dynamically allocated inside a function call void function() which is done using 'out parameters' in following code
struct my_struct {
int x;
} void my_function( my_struct** result ) {
my_struct* x = new my_struct{ 10 };
//...
*result = x;
}
Now i have a doubt, so if i want to print the return value from struct pointer, should i need to print it in the void function() or in the caller the function...
View 3 Replies
View Related
Mar 6, 2015
Here is the part of my code that I need to return two values. I am working on a roulette program and I need to return the choice and the number they are betting on. How can I use a pointer to achieve this?
Code:
int makeBet(char choice, int num){
printf("
What type of bet would you like to place? ");
printf("
Type n for number.
Type e for even/odd.
Type d for dozen.
[Code] ....
View 2 Replies
View Related
Feb 12, 2013
I am using pointer to display values of an array but its output is not correct example 23424,0, -323423 etc... whats the problem with my code:
Code:
#include<stdio.h>
#include<conio.h>
int main() {
clrscr();
int arr[10][10],rows,cols;
int* ptr;
[Code] ....
View 4 Replies
View Related
Mar 31, 2014
I have a doubly linked list, which reads in a set of coordinates x and y.
I need to pass these coordinates into a method called calculateImportance and execute Pythagoras on them. With this in mind I need to be able to access the pointers current, next and prev.
The issue I am having, is that I am unable to pass the pointers through to the method?
This is the list.h
#include <iostream>
class List {
private:
typedef struct node {
int xCoord;
int yCoord;
float importanceFactor;
[Code] .....
View 6 Replies
View Related
Aug 10, 2013
I can assign values to pointer character array like this...
Code:
char *array[4]={"abc","xyz","dgf","sdt"} ;
but the case is i don't know how to assign strings through key board ???? with using gets ,getchar or other suitable function
View 2 Replies
View Related
Mar 7, 2013
I am writing a C program to access a string into an array from a pointer array in Visual Studio 2010. Program is given below:-
Code:
#include <stdio.h>
#include <string.h>
void main() {
char data_a[6],data_b[6]="ABcde",*ptr;
ptr=&data_b[0];
data_a[0]=*ptr;
printf("%s",a);
}
I am getting some junk character first and then my actual data on console window. I want to where I am getting wrong and how to resolve it.
View 4 Replies
View Related
Sep 14, 2014
#include <stdio.h>
#define MAX_USERS 20
struct {
char ID[10];
char Name[40];
int Pos;
[Code] .....
I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.
View 9 Replies
View Related
Nov 19, 2013
I am having an issue with my sort function. This is one part of the Hash table program. The main issue is that I am trying to sort the pointer table after all of the values have been entered. The ptr_sort function is not a class function and so I am therefore unable to use the class variables psize and pTable. Is there another way I should be trying this? it is a Vector should I use the sort() function from the vector class in STL?
#include "/home/onyuksel/courses/340/progs/13f/p9/util9.h"
#include "/home/onyuksel/courses/340/progs/13f/p9/hTable.h"
#ifndef H_TABLE1
#define H_TABLE1
void ptr_sort ( );
[Code] ....
View 1 Replies
View Related
Jan 30, 2013
I am having a hard time with some of my homework, specifically regarding how to printf floats. I can't seem to print the number i want out using float, it just becomes a jumbled mess.
Code:
#include <stdio.h>
#define TICKER "LRCX"
#define PURCHASE_DATE "01/02/13"
#define SELL_DATE "01/30/13"
#define INVESTMENT_AMOUNT "10,000.00"
[Code] .....
Thats the code I currently have, I've probably tried everything to get the number to come out, but I just cant seem to figure it out. It should look like this, but with different numbers and stock:
Stock: MCD Buy Date: 01/02/13 Sell Date: 01/29/13 Buy Share Price: $89.40 Sell Share Price: $91.50 Shares Purchased: 111.86
Amount of Investment: $10,000.00 Value of Shares Sold: $10,234.90 Amount of Gain/Loss: $234.90 Percent Gain/Loss: 2.35%
However, this is how mine turns out:
Code::Blocks
Enter share purchase price for LRCX=>23
Enter the selling price for LRCX=>23
Stock: LRCX
Buy Date: 01/02/13
Sell Date: 01/30/13
Buy Share Price: -1.#R
Sell Share Price: -1.#R
Shares Purchased: -1.#R
Amount of Investment: 10,000.00
Value of Shares Sold:-1.#R
Amount of Gain/Loss:-1.#R
Percent Gain/Loss:-1.#R%
Process returned 0 (0x0) execution time : 2.864 s
Press any key to continue.
View 3 Replies
View Related
May 6, 2013
I have the following line of the code. Now I want to save the content to a string. Is there a quick way for me to do the conversion using the same arguments/codes of printf?
printf ("Some different radixes: %d %x %o %#x %#o
", 100, 100, 100, 100, 100);
View 3 Replies
View Related
Sep 5, 2014
#include<stdio.h>
void main()
{
int i=6;
printf("%d %*d
",i,i+9);
}
what is the out put?
View 2 Replies
View Related
Jul 17, 2013
I am having trouble with the printf in this function:
Code:
void print_orig_array(char string_array[MAX_PEOPLE][NAME_SIZE], int ages[MAX_PEOPLE], int length) {
int counter;
printf("Original list");
printf("
[URL] ....
Here is the output:
Am I missing something with the format specifier? How do I fix the 84 that gets pushed out?
View 2 Replies
View Related