bool isUnique(string _str) { bool char_set[256]; int len = _str.length(); memset(char_set, '/0', 256); for(int i = 0; i < len; ++i)
[Code] .....
I came across this code to find if string has unique characters...i didnt understand why they subracted ascii value of character '0' in the statement int val = _str[i]- '0' and what is happening with the statements...
I take each character in the sting and traverse the whole string .and if count is 2 i use break and conclude that its not unique and not otherwise...can i use this method or this is not efficient????
Im working on a script compiler and i need to handle different types of data. Actually different categories of items.
Let's say i have two categories: cat's and bird's. They are different and stored in different lists. And let's say there is a simple command: GIVE_FOOD_TO(animal_type, food_type) Animal type here can be either from birds category or cat's category.
And also let's say user gives command: GIVE_FOOD_TO(cat1, fish) and also for example: GIVE_FOOD_TO(bird1, birdfood)
Variable names could be anything, but im storing each variable name in std::map so later i can figure out with what animal current command is used.
When im parsing the script then i must know if user supplied either cat or bird. If i just would have cat's or bird's category then i would have only 2 lists and not a big problem to loop through either cats list or birds list and find out in what list the "cat1" is or in what particular list the "bird1" is. It would be in one or another.
But i have a lot of categories and looping through all of these lists (or std::maps) is slow and doesn't seem like a good. Just to find out in what list it's stored. I can't rely on variable names, they could be anything.
Big picture atm:
1) I have one BIG box which stores all of the categories
2) When i need to find out to which category the variable (animal_type) point's to i must get it quickly, dunno, std::map in std::map or something?
What i need basically is: I have different lists (each one is just a category for either birds or cats in this example) And when i have variable name, i must find out quickly in what particular category this item is stored. So i can work with it.
E.g. i have a log file in which there are many entries for appGUID. Now how many appGUID's are there, for this i have a code, but how many of them are unique, for this i don't have code.
Currently i have a system that will store user input into a txt file, and have a function that will compute the daily sales of the month(Check by system date month) and display the sales of the day and the grand total of that month.
Take for example, the system date now check that the current month is Apr. Below are my current output:
20Apr2015 $11.5 20Apr2015 $15.5 22Apr2015 $4.5 25Apr2015 $4.5 28Apr2015 $4.5 20Apr2015 $4.5 Grand Total $45
But my desired result should be as below
20Apr2015 $31.5 22Apr2015 $4.5 25Apr2015 $4.5 28Apr2015 $4.5 Grand Total $45
I need to find a string(&login=) from physical memory dump file.And i have to print the word or string following it.Is there any C# code for this problem?
My question is to write a complete program that will search a file of numbers(numbers.txt) for the smallest and largest numbers and then write the values to the screen using a single pass through the file. File only contains type int and holds at least one int. My questions are am I reading in the first number correctly? Where would I read in the second number to compare to the current max and min?
Code:
#include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { FILE *fin; fin = fopen("numbers.txt", "r"); //check to make sure file opened if(fin == NULL) }
This function buildTree that reads an text input (contained in the file named in argv[1]). Then, I am opening the file, reading character by character, if there is a new line ("if (token == ' ')") keep track of this line number and store it in a vector to access it later. Next it breaks it into a sequence of words (using any character other than a digit or an alphabetical symbol as the terminator). This is where I'm getting an error. I am then trying to add each character to a string and then when the token is a digit or an alphabetical symbol, then push the string into a vector so I can access it later. Is my logic right? error when pushing each word into a vector.
BinarySearchTree buildTree (char *argv[]){ ifstream file; vector<char *> V; int line = 0;
I have a specific byte (that is unsigned char) array, that I need to find in a very big file (2GB or so), currently I'm using:
size_t fsFind(FILE* device, byte* data, size_t size) { int SIZE = (1024 > size) ? 1024 : size; byte buffer[SIZE]; int pos = 0; int loc = ftell(device);
[Code] ....
Which seems to find proper result on first use, but on subsequent searches it seems to find invalid positions, is there something I'm doing wrong, or is there a better way?
Problem: I have to find the word "NAND" and then find the numbers inside the brackets because they are the inputs to that NAND gate. I have written a code below but that code can detect the fixed number of inputs. I need a code which can detect any number of inputs (whether 2 inputs or more than two). But i don't understand how do i do that?
My code:
Code: string input_str ("INPUT"), output_str ("OUTPUT"), nand_str("NAND"); while (getline( input_file, line )) { std::size_t guard_found = line.find(guard_str);
It appears that when you enter command line arguments or use fgets() to input a string you can assign that string to another string variable using the assignment operator. But when you read from a file, you can't do that, you get a segfault. It seems the only way to get around that is to malloc the string and use the strcpy function.
Code: #include <stdio.h> struct person { char *names[2]; }; void readFile(struct person p){ FILE *file = fopen("names", "r");
I'm working on a project, and I'm trying to fill in various vectors from a given input file. The input file looks like:
<catalog> <book id ="bk101"> <author>O'Brien, Tim</author> ....etc
My load vectors function looks like this: void load_vectors(vector<string>&id, vector<string>& author...etc)
I can't assume a limit on the number of books etc listed in this catalog, so I'm using the eof() function. However, I don't know how to write the loop to gather the correct strings and place them in the vectors.
Code: while(in.eof()) { string text; int index, index2; getline(in, text); int index = text.find("<author>"); int index2 = text.find("</author>"); a = index.lenght(); author.pushback[i] = text.substr(index + a, index2); }
My objectives for this program is to open and read a file "dict.txt" which has the following data:
4 dog pepper marker teapot
It needs to rotate the inner letters one to the right so you'd end up with "mrkear" etc, and then write those words into a new file "scramble.txt" one per line.I'm having a lot of problems understanding the program. Compiling is giving me a lot of warnings/errors.
Code:
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXW 10 //max number of words in file #define MAXS 81 //max size of string }
While I execute the fileprint function i was able to retrieve the record from the txt file. but at the end of the console im getting randoms number i have tried to understand what causing the problem. I have attached a screenshot....
Code:
void fileprint(){ Code: int c; struct student{ long id; char name[20]; int mid1;
Write a program that reads several strings from a file. Display the number of words then display each word as shown in the sample below. Assume that the maximum number of string in the file is 100.
Sample Input (.in): Smitty Werbenjagermanjensen. He was number 1!
Sample Output:
Total Number of Words: 6
Word[0] = Smitty Word[1] = Werbenjagermanjensen. Word[2] = He Word[3] = was Word[4] = number Word[5] = 1!
I need making a function that is deciphering multiple strings from a .txt file. The function is supposed to remove all instances of the first three characters from the string.
An example would be from l.pjkjsdfl.p[)sdfslkl.p ------> jkjsdf[)sdfslk
Basically it removes "l.p" from wherever it is in the string.
I am new to C++ and I don't know where to start from.
I wanted to improve the game from my last thread. I want to read and store a question in this format: Code: Who invented the BALLPOINT PEN?
A - Biro Brothers B - Waterman Brothers C - Bicc Brothers D - Write Bothers
But when I use fgets() to read the string, it reads all the ' ' literally instead of outputting a real newline. Like if it read the above question, I want it to print something like this:
Code: Who invented the BALLPOINT PEN?
A - Biro Brothers B - Waterman Brothers C - Bicc Brothers D - Write Bothers
I am trying to compare a string that i have entered with a set of strings that have already been stored in a file. I am using strcmp function but i am not getting the result.
Code: printf(" Enter string:"); scanf("%s",&m); ptr_file =fopen("abc.text","r");
The first line of my input file is going to contain some number "T" which will represent the "combination length" of a list of random words. (In this case, they are Taco Bell items). The first number on the second line represents the number of unique items on the menu to get, and the second number on the second line represents the number of unique items that are supposed to be bought.
Basically the input will look like this: 2 3 2 taco burrito nacho
And the output looks like this: burritos nachos nacho taco burrito taco
This is what I have so far:
Code:
#include <stdio.h> #include <stdlib.h> #include <strings.h> int main(void){ int N, T, K; char menu[N][20];
[Code] .....
What I am trying to get working right now is just to scan a file and put the strings into an array so then I can work on sorting the array. How can I add strings from a file into an array?
In a program, I have a text file (called MyDictionary.txt) which has thousands of words in alphabetical order. I need to make a C program that reads in this text file and then makes an array called char Words[# of total words in the text file][length of longest word].