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(),
a) Write a C-program that creates a chain of 10 processes and prints out their process ids and relationships. For example, process 1 is the parent of process 2, process 2 is the parent of process 3, process 3 is the parent of 4 and so on. Each child has to print out all her ancestors identified by the process ids.
b) Write a C-program that creates a fan of 10 processes. That is, process 1 is the parent of prcocesses 2, 3, 4, 5, 6 and so on.
I'm assuming that he means c++ since that's what we've been using. how to start this and what it means? Or where I can learn how to do this.
Ok, I got everything else to work in a two part exercise except for the 2nd part.
The first part had me take up to 20 grades, calculate total, average, and then list the grades with a '*' next to ones that were lower than the average... good to go.
Now in the 2nd part of the exercise I have to also associate a letter grade with the grades in the list. I have done a "if else" chain, but am having an issue with multiple arguments and not sure if I have gone the right route.
Code:
//Cameron Taylor #include <stdio.h> #include <math.h> #define MAXARRAY 20
I got everything in this code running except for my remove function. What the project does is adds or removes an integer to a chain of integers created by the user. My add function works the first time but after that if I try to remove or add I believe it is pointing to the improper location and I don't know how to fix this....
Here is my code:
Header: // adds "number" to the array pointed to by "arrayPtr" of "size". // Note the size of the array is thus increased. void addNumber(int *& arrayPtr, int number, int &size); // removes a "number" from the "arrayPtr" of "size". // if "number" is not there -- no action
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.
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.
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);
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
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??
#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.
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){
I need to search for a string in an array of objects, this is what I have but it does not seem to work, it always gives me the second string in the array instead of the one that i search for.
void binarySearch(Student S[], string name) { int first = 0; int last = 9; int middle; int position = -1; bool found = false;
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'
I need it to search a dynamic array which I build from an input file. When it finds the user-input string, I want it to store the line number, and continue searching, and record all lines that contain the user-input string.
Here is a link to my complete main.cpp, header file, and implementation file. The function I am having trouble with is "Bagger::lineSearch"
I am trying to implement a Task scheduler where i have n number of tasks. The Idea behind my task scheduler is that in a loop of queues of a vector, task should get enqueued to the shortest queue among the loop of queues, which is done by the following code.
#include <vector> #include <queue> std::vector<std::queue<int> > q int min_index = 0; task t // implemented in the other part of the program
[Code] ....
Next i am trying to extend this paradigm to reduce the overhead time of the scheduler, Instead of searching the shortest queue every time, search after some condition ie. search the shortest queue after 5 tasks gets enqueued to the shortest queue.
i need to do something like this
#include <vector> #include <queue> std::vector<std::queue<int> > q task t // implemented in the other part of the program while(q[min_index].size()!=q[min_index].size()+5) // check whether current min_index queue's size is increased 5 more times if not goto enqueue
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.
i am having difficulties doing this program. i dont know how to search for the value 80.
#include <cstdlib> #include <ctime> #include <iostream> using namespace std; class SortArray { public: int randomArray[]; int find(int randomArray[], int len, int seek);
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..)
It has been a while since I built a binary tree from scratch so I decided to do it. Everything works fine but this one function. When I enter a number to search it just keeps running and allowing me to keep enter numbers.
Code: void tree::search(int key,Node* leaf) { if (leaf == NULL) { std::cout<<"The tree is empty