C :: Linear Search Function Accessing String In A Struct?

Apr 5, 2013

I currently have a file which allows inputs to record different transistor types. I then have the task of accessing this structure, find a certain manufacturer ID, and print the information about this particular transistor.

My problem is accessing the array to search through.

Here is my code:

Code:
#include "stdio.h"
const int IDLEN=30; //All constant values defined
const int POLARITYLEN=3;
const int MAXSTOCKITEMS=10;
//First structure defined
struct TransistorRec {

[Code]......

The errors I am currently getting are on line 54 'expected primary-expression before "struct"' and on line 60 ' 'maunfacturersID' undeclared'

View 11 Replies


ADVERTISEMENT

C :: Linear Search Script - Calling Array Inside Of User Defined Function?

Jul 24, 2013

im tasked with creating a linear search script using functions on a 10 element array. the elements are to be supplied by the user as is the search target.

I understand how to create the array and gather that information from the user as well as howto set a variable for "target", this is what im calling it. Those two parts are simple enough.

I am not fully understanding the calling of an array in a function as a pointer. i semi understand the use of a pointer and howto call a normal pointer in a function. i also understand that an array is nothing more then a "special" pointer with a set of consecutive address blocks for the size of the array.

My first user defined function is simple enough

Code:
ReadArray(int A[], int size){
int i;
printf("Please enter %d integer numbers separated by spaces:
", size);
for (i = 0; i < size; i++)
scanf("%d", &A[i]);
}

Sso nothing out of the ordinary there. that should be a standard for loop and use of scanf, sadly prof has not covered ssanf or any of the other options so i am stuck using scanf for now. maybe someday down the line in a other program or after this course ill get the chance to learn about better options for gathering data from the user.

I am confused as to my next function:

Code:
void SearchArray(int A[], int target, int size);

I've not written any code here yet as im not sure if i should call the A[], or *A for the first type of the function?

If i call *A do i then use something like this for my search:

Code:
for (*A = 0; *A < size; *A++)
if (*A < target) or use A[] insteadA?

Code:
for (i = 0; i < size; i++)
if (A[i] = target)

View 6 Replies View Related

C++ :: Binary Search Or Linear Search For 3D Array

Oct 7, 2014

inputting a search array. I tried putting a binary search but I can't get it to work. everything else works up until I put the value I am searching for in the array, then it just crashes.

How it suppose to work: input 2 coordinates with a value each then it calculates the distance between them then it suppose to let user search the coordinates for a value and state if found which coordinate it is at.

#include "stdafx.h"
#include <iostream>
#include <iomanip> //for setprecision
#include <math.h>

[Code].....

View 3 Replies View Related

C/C++ :: Binary And Linear Search Program

Mar 30, 2014

// ***This program uses a binary search and a linear search to see if a 3-digit lottery number matches the number on any of the player's tickets.***//

#include <iostream>
using namespace std;

[Code].....

bunch of errors and completely lost. what it's supposed to look like.

View 4 Replies View Related

C/C++ :: Linear Search Not Found Output

Jul 3, 2014

How to return a message saying that the value searched for is not found. We had to pull the data in from a .dat, i won't let me attach it as a .dat so I attached it as .txt. I know my it's sloppy. I usually clean up what I can once it is working properly.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int ccnt;
int size = 10;

[Code] ....

Attached File(s) : dat45.txt (273bytes)

View 3 Replies View Related

C++ :: Accessing Inside Structure Via Struct Pointer To Struct Pointer

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

C++ ::  Accessing Struct Data In A Queue

Mar 24, 2013

I have a queue of structs. I would like to access one of the two pieces of data at the front of the queue that each struct maintains.

Here is some of my code:

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <queue>
using namespace std;

[Code] ....

What I am asking is how do I get the priority of the struct item at the front (lane1.front()), in this case?

View 8 Replies View Related

C/C++ :: Segfault When Accessing Member Of A Struct

Mar 18, 2014

The program I'm working on is a very basic relational database. I've isolated my problem for simplicity. I get a segfault right here when I try to access db->relationCount. I tried printing db->relationCount from within loadDB and that worked,

[code]
loadDB(db, configFile);
printf("%d",db->relationCount);
fflush(stdout);

View 5 Replies View Related

C/C++ :: Accessing Elements Of Struct Array

Dec 9, 2014

I've been working for some number of days on this code to take information about movies from both a file and the user, store the infos in an array of structs, and at the end, write all the info out to a file. I'm having some problems with an error message reading:

"prog.c:102:11: error: subscripted value is neither array nor pointer nor vector"

this error occurs in many lines (which I will label specifically below -- they are everywhere where I am trying to access/modify an individual element of a struct element of the array).

A few examples of where I am having the problems are lines:
39, 52-55, 70, 72, and 86 (and more of the same exact variety).

I am obviously rather systematically doing something wrong, but I am quite certain all of these are the exact same mistakes.

I pull up also 2 or 3 other errors, but I don't think they are related and should be able to fix them quickly once I work out this conundrum.

#include <string.h>
#include<stdlib.h>
#include <stdio.h>
int moviecount =0;
typedef struct{
int year;

[Code] .....

View 5 Replies View Related

C++ :: Accessing Private Members Of Same Struct Type

Mar 26, 2013

I've been reading the tutorials on Friendship and Inheritance [URL] ..... but I still don't understand why I can't access members of the same struct type.

bool wordBeginsAt (int pos) {
if (pos == 0)
return true;

///use the 'message' string
Message go;
return isAlphanumeric(go.messageText[pos]) && (!isAlphanumeric(go.messageText[pos-1]));
}

The code above is located in a source file, where the function isAlphanumeric passes a char value, and Message is the struct containing the string I want to access. Below is the declaration of the struct and string located in the corresponding header file.

struct Message{
.
.
.
private:
std::string messageText;
};

My frustration comes when I try to call and assign messageText like the tutorial does to its private members, but I keep getting an error saying I can't access the string because it is a private member. Is there a way to access the string without having to pass it through the function wordBeginsAt?

View 6 Replies View Related

C++ :: Accessing Pointed-to Value In A Struct Vector Of Pointers?

Apr 30, 2013

I have a vector (structures) in a struct (instances). I make a declaration of this struct called instance. The vector is a 3-layer vector of pointers, like so:

vector < vector < vector<scene::IAnimatedMeshSceneNode*> > > structures; (The type is from Irrlicht 3D). I have 3 nested "for" loops which looks similar to the following:

for (int a = 0; a < instance.structures.size(); a++) { /*note:vector size previously set*/
for (int b = 0; b < instance.structures[a].size(); b++){
for (int c = 0; c < instance.structures[a][b].size(); c++) {

if (1) { //checking value of variable not included in snippet

(instance.structures)[a][b][c] = smgr->addAnimatedMeshSceneNode(fl);
(instance.structures)[a][b][c]->setPosition(renderPos);
}
}
}
}

The problem is in these two lines, I think:

(instance.structures)[a][b][c] = smgr->addAnimatedMeshSceneNode(fl);
(instance.structures)[a][b][c]->setPosition(renderPos);

These are currently referencing the pointers, it seems. The program compiles but crashes at this point. I need them to reference the values of the pointers. Problem is, I don't know where to put the dereference operator (*). Where should it go?

View 4 Replies View Related

C :: Strstr Function / Search And Replacing New String

Sep 23, 2013

Code:

#include<stdio.h>
#include<string.h>
#define MAX 25
int main(void)
{
int ch;

[Code]....

i think that cause this program to be error.because when i using the reference from internet, the program was executed for sure.This code what i mean

Code:
#include <stdio.h>
#include <string.h>
#define MAX 10
int main () {
int ch;
char str[] ="This is a simple string";
char str1[MAX];
char str2[MAX];

[Code]....

and rather than that i didnt have anymore idea to make that replacing string.

View 6 Replies View Related

C/C++ :: Strrchr Function - Search For A String From The Reverse

Feb 27, 2014

I understand that the strrchr function is supposed to search for a string from the reverse. Unfortunately, mine isn't doing that.

#include <stdio.h>
#include <conio.h>
int main() {
char userinput[100] = "null";
char searchchar;
char *s;
char try_Again;

[Code] ....

View 5 Replies View Related

C++ :: Ioquake3 Engine - Accessing Limited Struct Fields

Feb 29, 2012

I'm currently working on the ioquake3 engine . The ioquake3 engine is separated into 2 different main threads at runtime: the gamecode and the engine. Both are communicating but not all information and my problem resides here.

In the gamecode, there's a struct called gentity_t which contains a lot of fields:

Code:
typedef struct gentity_s gentity_t;
struct gentity_s {
entityState_ts;// communicated by server to clients
entityShared_tr;// shared by both the server system and game
// DO NOT MODIFY ANYTHING ABOVE THIS, THE SERVER
// EXPECTS THE FIELDS IN THAT ORDER!
//================================
struct gclient_s*client;// NULL if not a client

[Code] ....

This whole entity is passed to the engine at runtime, but only the first two fields are declared for the engine:

Code:
// the server looks at a sharedEntity, which is the start of the game's gentity_t structure
typedef struct {
entityState_ts;// communicated by server to clients
entityShared_tr;// shared by both the server system and game
} sharedEntity_t;

My problem is that I need to access the health field of gentity_t from the engine. Technically, this is possible, but the health field is not declared in sharedEntity (which is the same memory address than gentity_t in the gamecode), so this is not straightforward.

I am looking for an elegant way to do this, and my constraint is that I must not edit the gamecode, only the engine.

The solutions I've thought:

- Just copy the whole gentity_t fields into sharedEntity_t. This would work I think but would be redundant, and I would like to avoid copying this huge set of fields.

- Include the two headers files declaring the gentity_t and sharedEntity_t structs, and create a Getter and a Setter functions that would cast a gentity_t over a sharedEntity_t and return/set a field. The problem is that I can't simply include them because they are both including some common headers files and this produce a recursive include error (and I can't modify the files to add a check, these are normally in the gamecode).

- Directly access the health field using a clever memory pointer, but I don't even know if that's possible given the huge number of fields prior health with many different types?

View 2 Replies View Related

C :: Parsing Binary Data File By Casting A Buffer - Accessing Double From Struct

Jan 4, 2014

I am parsing a binary data file by casting a buffer to a struct. It seems to work really well apart from this one double which is always being accessed two bytes off, despite being in the correct place.

Code:

typedef struct InvoiceRow {
uint INVOICE_NUMBER;
...
double GROSS;
...
char VAT_NUMBER[31];
} InvoiceRow;

If I attempt to print GROSS using printf("%f", row->GROSS) I get 0.0000. However, if I change the type of GROSS to char[8] and then use the following code, I am presented with the correct number...

Code:

typedef struct example {
double d;
}

example;
example *blah = (example*)row->GROSS;
printf("%f", blah->d);

View 7 Replies View Related

C :: How To Do Search In Struct

Jul 9, 2014

So i create a simple structure,that has a firstname, lastname, age, dateofbirth.I would like it if i type what I am searching for print out there is one or not.But i have some trouble with equals(in array).. i type in the same "keresettnev" as "tanulok[i].Firstname" but it thinks not the same. (it works with age..)

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

struct student {
char *Firstname[40];
char *Lastname[40];
int age;

[Code] ....

View 12 Replies View Related

C :: Binary Search Tree - Struct Data

Oct 24, 2013

I was working with binary search tree and came up with the solution:

Code:
#include<stdio.h>
#include<stdlib.h>
typedef struct data {
int x;
struct data *left;
struct data *right;

[Code] .....

View 6 Replies View Related

C++ :: Accessing Data Outside A Function

Feb 11, 2013

I was wondering what the best way was to access data outside the function it was created in. I have the user input a data in a custom namespace function, and now im trying to access all those data points in a different function.

View 9 Replies View Related

C :: Search File For String

Aug 22, 2014

I should state that I am recently new to C programming. I have dabbled with Python in the past, but nothing formal. I am taking a C programming class, but it is an introductory course. As such, the instructor is moving extremely slow through the material.

With this program, I am trying to search a given text file (line-by-line) for user-submitted data. I then want to be able to store which line that data was found on. The program runs, but it always results in "Sorry, couldn't find a match." Even if it shouldn't.

Code:

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
}

[code]...

I should probably explain my overall goal with this program.I would like to write a program that will calculate the molecular weight of a compound. I expect the user entered molecular compound to be something like this: CH3COOH (An equivalent entry could be C2H4O2)Also, it needs to be case sensitive because the chemical formulas are case sensitive.

The output will be "The molecular weight of CH3COOH is xxx.xxxxx grams".I have two text files as well. One contains a list of all chemical symbols, and the second is a list of all atomic weights in the same order as the first. I want to place the user inputted data into an array, then search for each element of that array in the chemical symbol text file. It will show which line it was found on, then I can use that line to grab the atomic weight from the second text file.

View 5 Replies View Related

C :: Search Chain In String

Mar 23, 2013

i have a work to do that consists on a given char pointer to a chain and a also given char pointer to a string. i have to search that chain in the string, and return the position where the beginning of the two it's equal. but only if they are equal.

example: string is "abcd" and the chain is "bc". want to find the chain, and if it exists, the position return will be 2. in the work it says that we should use sprintf() too. here is my code, which is incomplet yet.

Code:

char* pos(char* C,char* S){
char *str = S;
char *chain = C;
int i, j, temp;
int lengthStr = strlength(C);
int lengthChain = strlength(S);
}

[code]....

my doubt is how to use sprintf() and where. if i have to use malloc() and free(),

other examples:
pos(AGA,CTGCA)
return:
0

pos(AGA, ATAGATA)
return:
3

pos(AGA AGATAGA)
return
1 5

View 6 Replies View Related

C++ :: Undefined Reference Error When Accessing Static Variable Inside Member Function

Feb 10, 2013

I am modifying a set of static variables inside of the class's member function. The static variables are private. An example of what I'm doing is as below,

utilities.h
-----------
class utilities {
private:
static int num_nodes;

public:
void parse_details(char* );

[Code] ....

I get a compilation error in the function void utilities::parse_details(char* filename)

which says: undefined reference to `utilities::num_nodes'

compiler: g++

View 2 Replies View Related

C :: Binary Search With String Algorithm

Oct 3, 2013

I'm trying to use the biSearch function to search for a keyword in the dictionary.

Code:
int biSearch(Dict DictEntries[MAXENTRIES],int start, int finish,char *keyword) {
int mid = (start+finish)/2;
int index = strcmp(DictEntries[mid].key,keyword);
printf("%s=%s
",DictEntries[mid].key,keyword);

[Code] ....

View 4 Replies View Related

C++ :: BAC Calculator - String Stream Search

May 14, 2013

I am working on a project which is a fairly simply BAC calculator. I am attempting to grab data from a text file, which contains state abbreviation, maximum BAC before aggravated, and minimum license suspension. The text file looks like

#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <stdio.h>
#include <ctype.h>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
#include <sstream>
using namespace std;

float MALE_RATE = 0.68, FEMALE_RATE = 0.55, LEGAL_LIMIT = 0.08;
//percent of body weight which holds alcohol

[Code] ....

The code I am struggling with is the getline and stringstream which is near the bottom.

The output I am getting is

The maximum BAC before aggrevated DUI in AL is .15
The minimum penalty in AL is 90 day suspension of license

I get that for every state I type. I know it is reading the first line, but something in my code does not allow it to read the other lines

View 1 Replies View Related

C++ :: How To Search For A Specific Character In A String

Feb 4, 2015

i'm doing a validation exercise program. Just a question, how do i search an inputted string for a certain character?

For example:

Hello.World

I wanna determine and find out the where the '.' sign is.

I'm doing an if-else conditions, i need to determine where the character is located and make sure it doesn't repeat.

View 4 Replies View Related

C# :: Search / Highlight And Replace String

Jan 11, 2014

I am a beginner of c#.. i have try to made a windows notepad and face some issues. I want to add find string from open file... and also want to replace it with a new string... Is there any simple and easy solution to this problem??

View 7 Replies View Related

C :: Search A Requested String And Output Into 16 Byte

Mar 20, 2013

So basically here I have a menu in my C program and if I were to select option 2, I would enter a string up to 30 characters and it would output each block of 16 bytes should be shown which contains a character in the requested string. However, when I compile and run the program and search for the string, nothing happens. what I may be doing wrong?

Code:

else if (select == 2){
printf("Enter a string of up to 30 characters: ");
scanf("%s", &userstr);
//Compares both user's string and file string
for (i = 0; i < size; i++){
if (strcmp (buffer, userstr) !=0){

[Code]...

View 6 Replies View Related







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