I have to search an array of struct students on the basis of their first names, last names and roll numbers .. so far i am done with the input of the student first , last names and roll numbers . I have problem in searching the array ..
Basically I initialize an int array of size 10 with zeros. Then element 7 is changed to 1. Via cin I collect a user input (integer) which is the number to be searched.
Now the problem is that the search function from the book is somehow not working. I added a function to see how the array looks like and there is definitely one element with value 1 that should be found, but it simply isn't. The function always returns -1 (element not found).
The program compiles, but doesn't work as it is supposed to.
//******************************************************** // search algorithm for arrays //******************************************************** #include <iostream> using namespace std;
I have a linear search algorithm set up to search through an array of class objects it works but the output does not match, when i search for a particluar name in the array the 1st and third values int the array are found but the second value is not found..
below is my code:
int linsearch(string val) { for (int j=0; j <= 3; j++) { if (player[j].getLastName()==val) return j ;
I'm trying to open a text file from my computer and randomly output a random line of text (string) onto the console. How do I go about doing this?
So for example, if my text file, "StringTextFile.txt" had 50 rows of strings datas (not integers or chars), how would I randomly generate a line of word from the 50 rows of words in the StringTextFile.txt and output it onto the console?
This is how far I've gotten, which isn't much, but somewhere. I don't even know if my code even makes sense, at this point I'm just randomly shoving code together.
My program generates an array of random numbers. I want to then search a specific number within the array. If the number is in the array then a message apopears on the console saying that its there. I'm using the binary search algorithm to do this.
#include <iostream> #include <ctime> #include <cstdlib> #include <iomanip> #include <cstring> using namespace std; int size; int getSize() { return size; }
Set found to false. Set position to -1. Set index to 0. While found is false and index < number of elements If list[index] is equal to search value found = true. position = index. End If Add 1 to index. End While. Return position
I am having a problem printing out the results for my code, It is supposed to print out the largest and smallest value in the array, but keeps giving me a value not entered and I don't know why.
//This program lets the user enter 10 numbers and then display the highest and lowest number.
#include <iostream> #include<stdio.h> using namespace std; int main() { const int NUM_ENTERED = 9; int number[NUM_ENTERED], highestValue = number[0], lowestValue = number[0], count=0;
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 */
I am working on an assignment identical to another post from a couple years ago, for reference here is the thread:
array of pointers to structures sorting addresses by zip code
They way it is written on that thread is almost identical to the way the teacher implied to have it done (only wrote part of the input block). But I am having an error:
When it gets to the output section it outputs then next name along with the zip code... I tried strncpy and strxfrm but both cause more problems than they did work.
The last part of the project is to have the output put out in order of least zip code to most zip code (00000<99999), so this is causing me a real problem and I do not see what exactly is making this happen.
Here is my code (we dont HAVE to use gets but professor suggested using it for this assignment, next lab is to rewrite this using files and fgets rather than I/O redirection):
I have not started the sorting code because I cannot get past this, but once I have proper zip codes I am sure I can make a sort function no problem.
I am using xcode with some breaks to read variables as various points and do not notice anything wrong until it makes it to the output functions, although this page briefly pops up between input and output functions when the breaks are up:
I am trying to pass a struct through an array to another array from one microprocessor to another microprocessor and then dereference that array to update the same exact struct on the other microprocessor.My goal is to always have values inside of both structs while sending any updates to the struct on the other microprocessor in the mean time but I seem to be looping through the data and the members of the struct seem to be cleared out after every clock cycle. I can verify this by the flashing of my leds which the struct controls.
It doesn't make sense to me why this is working. The way my mind is thinking about this is that vertices is an array of type VertexPos, so then why can it be initialized with objects of type XMFLOAT3?
What I'm trying to do with this code is an address book and I have an array of pointers which are returned by malloc whenever I need to add an extra entry in the address book. What I need to do is search for a specific entry using bsearch. I've got an inqSort() function that sorts the table and runs normally, but my program crashes when I try to use bsearch.
Every time an entry is inserted, I inqsort() the array so it's always sorted, and it works as expected. But when I try to call findEntryUI(); from the main() function, the program crashes after entering the name I want to search.
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.
struct Speaker { static int numElem; string name; int number; // Phone string topic; float fee; };
// IN main() FUNCTION Speaker s[10];
The goal is for numElem to keep track of how many of the 10 elements are in use. However, I'm not sure the proper way to access the element, if it's even possible.
I want to delete selected records from struct array using cstring reading from files. Here I read my records to stud struct then assign non-deleted to stu struct but its not deleting as desired...strcmp is giving 25
while(cont=='Y'){ cout<<"Enter student ID to delete: "; cin.ignore(); cin.getline(id, 15,
[Code] ....
I did some debugging effort and I found here is the problem..the stud[0].ID and id is not same but why? I am giving in same id and both char array lenght is 15
while(cont=='Y'){ cout<<"Enter student ID to delete: "; cin.ignore(); cin.getline(id, 15); cout<<strlen(stud[0].ID)<<" "<<strlen(id)<<endl;///---> lenght 1 is 10 ///---->lenght 2 is 8 cout<<strncmp(id,stud[0].ID, 10 )<<endl;
Okay so I have a question. Lets say I want to create arrays of exact size for abstract data type members. For example:
struct student { char name[10]; int idNumber; };
My question is how to declare this array as null so that later i can give it an exact size to match the length of the name. if it were not a part of the struct i would imagine that the code would look something like this:
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;
You should be able to enter those fields, and after some time when while loop is stopped (when u press n) it should print out that PhoneBook bellow. I don't understand what is the problem but I think it is that Display function.