C :: Array Of Structures And Passing Pointers To Structs

Feb 24, 2013

Background: I'm writing a convolutional encoder (and decoder, eventually) for a microprocessor (PIC24), for which I'm using structs and pointers to move from state to state. So far as I'm aware, everything I'm using in the PIC involves nothing other than ANSI C.

I have a little experience with structures, having written a linked-list program for a class a couple years back, but nothing since and never used structure arrays. I have the feeling I'm missing something basic here, which is what's so frustrating. The most confusing error (and I suspect the root of most of them) is the 'state undeclared', which I just can't figure.

The errors I'm getting are:

encoder.c:11: warning: 'struct memstate' declared inside parameter list
encoder.c:11: warning: its scope is only this definition or declaration, which is probably not what you want
encoder.c: In function 'state_init':
encoder.c:22: error: two or more data types in declaration specifiers
encoder.c:25: error: 'state' undeclared (first use in this function)
encoder.c:25: error: (Each undeclared identifier is reported only once

[Code]....

Code:

Code: //Includes
#include <stdlib.h>
//------------------------------------------------------------------------------
//Creates state machine and passes back pointer to 00 state
void state_init(struct memstate* startpoint)
{
extern struct memstate
{
char output0; //output if next input is 0

[code]...

NB: I'm aware that at the moment, this code will do nothing except spin round that do-while loop. Once it's actually compiling I'll drop in some simple button-based test code so it'll check for the correct output.

View 9 Replies


ADVERTISEMENT

C++ :: Passing Data Structures To Function Pointers And Get Values

Sep 26, 2014

typedef struct example_dt_struct {
int a;
float b;
char* c;
};
typedef void(*func)(example_dt_struct *s, int e, int f);
void f(func *n){}

how can i use example_dt_structure with my function pointer into f()

View 5 Replies View Related

C++ :: Pointers To Array Of Structs

Feb 14, 2013

I have an assignment where I need to use pointers to do a few things and I am a little confused on the syntax of it all. My question is how do you use a pointer to point to an array of structs.

For example

struct info{
char firstName[15];
char lastName[15];
};
main() {
info person[4];
cout << "The third letter of the second persons first name is: "; // ?????
}

how would I define a pointer to point to the third letter of first name the second person in the "person" array.

View 2 Replies View Related

C :: Passing A Pointer To Array Of Structs

Nov 20, 2013

what I am trying to do is to pass to a function the address of an array of structs, so I can later modify the items within the struct, within the array

Code:
typedef struct { //A struct of name auctionint bidder;float bid;} auction;
void myFunction (auction * auctionItem[]){(*aucItem[x]).bid = y;(*aucItem[x]).bidder = z;}
int main(){auction theItems[10];
myFunction(theItems);} Where x, y, and z can be any number.

When I try to run my code the IDE (I'm using Code::Blocks 12.11) does not give me any errors, but it does give me a warning:

warning: passing argument 3 of '<function name>' from incompatible pointer type [enabled by default]

and the note:

note: expected 'struct <struct name> **' but argument is of type 'struct <struct name> *'.Also, when I run the program, it will crash and return garbage.

View 6 Replies View Related

C :: Array Containing Pointers To Structures?

Aug 9, 2013

How do I store pointers to a struct in an array ? I am using sprintf to concatenate some values together and then output it to an array in its 1st argument. A portion of my code is shown below.

Code:

int count = 0;
struct addx {
int a;

[Code].....

View 1 Replies View Related

C++ :: Passing Array Of Pointers From A Function To Main

Nov 21, 2014

I have a a group of text files that are used as input into a program. Another very similar program needs the same data in a different input format. I am writing a program that will read in each line of data and parse it. I have successfully written the program in main() such that it will read until the end of file. However, I am trying to re-write the program such that the algorithm is in an external function and will read one line at a time and then pass all of the character strings to the main program. The program will not compile and I am positive it has to do with an incorrect use of arrays in passing the variable "token". I am attaching a copy of the main program and the function.

#include <iostream>
#include <fstream>
#include <cstring>
#include <stdio.h>
void Line_Parse(std::ifstream&,std::ostream&,const char* token);
int main(int argc, const char * argv[]) {

[Code] .....

View 2 Replies View Related

C/C++ :: Pointers And Structs

Dec 14, 2014

What the second print statement prints

main() {
struct s1{
char *str;
int i;
struct s1 *ptr;

[Code] .....

I executed the code and the output was some number(for second printf) but it should print a string.

View 3 Replies View Related

C++ :: Passing Structs And Functions All In Same

Mar 8, 2013

I think i am getting confused with passing structs and functions all in the same...When I run through the program (it compiles), the functions that add coins do not add, but rather just replace an old value with a new one.

#include <cstdlib>
#include <iostream>
using namespace std;
struct coinbox {

[code].....

View 1 Replies View Related

C :: Structs - Implement In With Pointers And Functions

Feb 23, 2013

I have a struct and I want to implement in with pointers and functions.

What is the corect syntax? For example:

Code:
typedef struct XYZ
{

int x;
int y;
int z;
}XYZ_t;

int func( using the XYZ_t struct)

[Code] .....

View 5 Replies View Related

C++ :: Memory Addresses Of Pointers To Structs

Apr 19, 2014

I have this struct declaration to create a linked list

struct node {
string y;
node* next;
};

If I create a linked list of 3 nodes

A->B->C->NULL

A->y is "a"
B->y is "b"
C->y is "c"

Since they are consecutive in memory. How far apart are the strings in memory?

I tried doing something like

int n = &(head->next->x)-&(head->x);

The problem is that I got 6 while debugging and 2 otherwise.

View 1 Replies View Related

C/C++ :: Regarding Pointers To Structures And Referencing?

Mar 24, 2015

concepts on pointers to structures and referencing for the following two lines.

//address of the variable "struct UIP_IP_BUF" is assigned as srcipaddr
uip_ds6_nbr_add(&UIP_IP_BUF->srcipaddr,
//data type "uip_lladdr_t" pointer points to the address of array an "nd6_opt_llao" with size UIP_ND6_OPT_DATA_OFFSET
(uip_lladdr_t *)&nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET]

View 5 Replies View Related

C :: Passing Structures To A Function

Feb 26, 2014

I am bit confused in passing the structure to a function. I made a small code and it doesn't build !

Code:
#include<stdio.h>
struct Compute_off_Time(struct WHATTIME);
typedef union _Time {
unsigned long int Value;

[Code] ....

View 1 Replies View Related

C++ :: Pointers Structures And Strings - What To Do With Spaces

Feb 13, 2013

This is my program and i dont know what is the better strategy to display the output perfectly align with the title, when i input a long variable or short the variable move and it does not align with its title. what can i do.

#include <iostream>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cstring>
#include <iomanip>
using namespace std;
struct book {

[Code] ....

View 1 Replies View Related

C++ :: Project Combining Arrays / Pointers And Structures

May 6, 2014

Write a program that uses a record structure to store a Student Name, Student ID, Test Scores, Average Test Score, and Grade. The program should keep a list of test scores for a group of 6 students. The program should ask for the name, ID, and four test scores for each student. Then the average test score should be calculated and stored. The course grade should be based on the following scale:

Average Test Score Course Grade
------------------ ------------
90 - 100 A
80 - 89 B
70 - 79 C
60 - 69 D
59 or below F

A table should be displayed on the screen listing each student's name, ID, average test score, and course grade. Implement with functions.

My code runs but it isnt returning anything (readable/correct) and i have no clue why. This is what i have so far:

#include <iostream>
using namespace std;
const int columns = 4;
struct StuRec //user defined datatype {
int id[6];
char names[6][20];

[Code] .....

it compiles completely but at the end instead of showing the student name ID average score and class grade it shows.... [URL] .....

View 2 Replies View Related

C/C++ :: Project Combining Arrays / Pointers And Structures

May 5, 2014

Write a program that uses a record structure to store a Student Name, Student ID, Test Scores, Average Test Score, and Grade. The program should keep a list of test scores for a group of 6 students. The program should ask for the name, ID, and four test scores for each student. Then the average test score should be calculated and stored. The course grade should be based on the following scale:

Average Test Score Course Grade
------------------ ------------
90 - 100 A
80 - 89 B
70 - 79 C
60 - 69 D
59 or below F

A table should be displayed on the screen listing each student's name, ID, average test score, and course grade. Implement with functions.

My code runs but it isnt returning anything(readable/correct) and i have no clue why. This is what i have so far:

#include <iostream>
using namespace std;
const int columns = 4;
struct StuRec //user defined datatype {
int id[6];
char names[6][20];
int scores[6][4];
double avg[6];
char grade[6];
}; //semi-colon required

[Code] ...

View 8 Replies View Related

C++ :: Outputting Data From File Into Structs And Arrays Of Structs

Apr 15, 2013

I am having a lot of trouble being able to get data from a file and input it into given structs and arrays of structs and then outputting the file. We are given a file that contains 96 lines and looks like this:

Arzin, Neil
2.3 6.0 5.0 6.7 7.8 5.6 8.9 7.6
Babbage, Charles
2.3 5.6 6.5 7.6 8.7 7.8 5.4 4.5

This file continues for 24 different people and then repeats with different scores (the second line).
The first number, in this case is 2.3 for both people is a difficulty rating. The next 6 numbers are scores.

We are given this data in order to set up our structs and arrays and my code:

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main () {
ifstream inFile;
inFile.open("C://diveData.txt);

[Code] .....

View 1 Replies View Related

C :: Create Array Of Pointers To Pointers Which Will Point To Array Of Pointers

Feb 28, 2014

I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried

Code:

int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",

[code]...

the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..

View 4 Replies View Related

C :: Passing Pointers Into Function?

Dec 3, 2013

I want to scan numbers in from within a function, but have access to them in main, so I tried using pointers to do so:

Code:
// Path Of Exile socket colours simulation
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

[Code].....

View 9 Replies View Related

C :: Passing Pointers To Functions

Feb 28, 2015

I have been struggling with pointers. I am trying to write a program that first asks a user to input a filename. It then checks if the file exists and if it does it passes a pointer to the next function. The next function then asks the user for a specific word to look for and the function will search a text file for the word and do some other operations. My problem is that I do not understand how to use the pointer returned by my first function as an input to another function.

The following code has the first function file_check() and the second function word_search() which I think the way I am declaring it is the problem.

Code:
FILE *file_check();
void word_search(FILE *);
int
main(void) {
FILE* check= file_check();
// word_search(check);

[Code] ......

View 6 Replies View Related

C :: Passing Arrays To Other Data Has Pointers?

May 7, 2013

I am looking for an example of when passing arrays to other data that has pointers,

I understand the terms I would just like to see a small example of code that actually demonstrates this process.

View 4 Replies View Related

C++ :: Passing Pointers By Reference To Function?

Mar 4, 2013

If f1 and f2 are two user defined functions.

main(){
int *p;
f1(&p)
}
f1(**p){
f2(&p);//

If I've to pass the pointer by reference again in another function, will I've to do something like this?

}
f2(***p){
**p = NULL;
}

View 3 Replies View Related

C :: Using Typedef Struct And Passing Pointers To Functions

Mar 3, 2013

I am having problems with passing my values through functions.

Here is my code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void test(int**);
void test2(int**);

[Code]....

View 8 Replies View Related

C++ :: Transfer Ownerships Between Objects (passing Arguments) Using Raw Pointers?

Sep 4, 2012

Code:
void Class1::Func(shared_ptr<type1> parameter)
{
}
or
void Class1::Func(const shared_ptr<type1>& parameter)
{
}
or
Should I ever pass arguments/parameters to other objects using shared_ptr's or raw pointers?

View 3 Replies View Related

C++ :: Array Of Structs With Constructor?

Apr 1, 2013

I can't seem to remember everything I should about constructors. I'm looking for a way to create an array of structs, using a constructor. My code should explain.

struct myStruct
{
private:
int structInt1, structInt2;

[Code].....

View 2 Replies View Related

C++ :: How To Qsort Array Of Structs By One Of Its Members

Mar 31, 2013

I am versed in qsorting struct members within a struct instance, as in the example below:

Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
struct item_database {

[Code]....

What I CANT do however is to sort an array of structs by one of its members. This is a complete different problem even if it sounds similar.

In other words, the problem is this; Say we have a struct:

Code:
struct item_database {
int key;
string token;
};

Then we declare an array of this struct in the heap:

Code: item_database *idptr = new item_database[700000]; and initialize its values.

How would one go about sorting this heap array of structs by its member function "token"?

I used the following call to qsort (standard library) and call to the compare function but it doesnt work:

Code:
qsort (idptr, 1000, sizeof(string), compare);

Code: int compare (const void* a, const void* b){
if (*(char*)a >= *(char*)b)
return 1;
else
return -1;
}

Or in more lamens terms say we have the following stuct instances:
Key: Token:
1 Hello
2 World
3 How
4 Are
5 You

Then I need those structs to order according to token (alphabetically, increasing or decreasing depending whats in our compare function).....

View 3 Replies View Related

C :: Adding Elements To Array Of Structs

Mar 6, 2015

I have a structure product_array *pa that contains a pointer *arr to an array of structs and count that adds 1 when a new product is added (set to NULL initially). I have to write a function which adds a new product entry to that array. One product entry has *title, *code, stock and price parameters. The array is dynamically allocated and I’m supposed to:

1. Reallocate space for array.
2. Update product_array.
3. Initialize it.

Also, code should be truncated to 7 characters.Products can be added multiple times, so the initial size is unknown.

Code:

void add_product(struct product_array *pa, const char *title, const char *code, int stock, double price)
{
for (int i = 0 ;; i++){
pa->arr = realloc(pa->arr, sizeof(struct product_array));

[code]....

View 3 Replies View Related







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