C :: Program To Move Strings From 1 File To Another
Mar 5, 2013
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
}
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 have to make a 8-puzzle and I got the algorithm i just dont know how to restart the program every time i type the move of the blank place in the 3x3 puzzle so i dont have to make 10000 lines to solve the puzzle
I am trying to resize a bmp image by FACTOR times. I got the width resize working correctly but for the height I need to print each row of pixels or 'RGBTRIPLE' FACTOR number of times. I am pretty sure I have the fseek line in the right spot (marked here) I just don't know how many bytes to move it by I tried 1 I though 1 byte past the end would move the pointer to the next line but that did not work. This is for a class so please no code. Here is my code.
I am trying to get this code eventually to read in a maze file to move the smiley face around in. But right now my current snag is the yes or no to enter the for loop.
#include <iostream> #include <windows.h> #include <conio.h> #include <time.h> using namespace std; int main() { int name; char ans;
I am not a programmer, C-wise. Mainly a shell scripter. any C program that I can use that can work like UNIX strings | grep "pattern"...At the moment, on a binary file, I am using UNIX strings and then grep for a pattern and print out that line and does some awk -F":" thing. This is manageable for when the binary file is 50M but not for where files are 100M and above. I mean it still works but takes longer since strings work on the entire file.
Basically the information that I am trying to extract from the binary file is some type of header that is contained in a file. I am thinking of maybe writing a 'simple' C program that will read the first few bytes of the binary file and then print the line that contains the string that I am looking for. I don't believe the header is at the end of the file but more in the beginning. I am wanting to extract the header information to be able to rename or make a copy of the binary in a more user-friendly name.
Any good reference/link to a sample program on reading a binary file maybe. Main reason why I am wanting a C program is because the binary file can be on Windows or *nix.
I know there is a function for comparing string but i am making it to just improve my concepts.error : 2 is coming as answer when i put same sting in both place.
'Write a program to match the user input string with the contents of text files and give the result as to which files contain the input string. This has to be done by using finite automaton.' (Any language can be used) So basically, the user will input a string (in the command line or a gui) and "we must pass the text files to the DFA" (I'm double quoting this because it's precisely what my professor told) and then display those files which contain the string. The string can be hard-coded, ie,the user will get the output file that contains a specific string. ex: 'hello'. The problem is, I have never done any program on DFA so I'm at a loss. how to write the program. Should I read the files first and then use some 'switch' or 'goto' conditions for the DFA? Below is a code I found on the internet for simulating a DFA accepting a specific string.
Code:
s: accept = false; cin >> char; if char = "m" goto m; if char = EOF goto end; goto s; m: accept = false; cin >> char; if char = "m" goto m; if char = "a" goto a; if char = EOF goto end; goto s; }
I'm working on a program that provides a number of utilities for strings, but I keep getting segmentation faults and I cannot tell why. strContains works fine, but basically the rest of my functions throw seg faults.
My assignment is : Please use C type strings ( array representation of strings). Write a program that will ask the user to enter a string. It will then regard that string as a worked-on string and allow the user to perform the following editing functions on it:
s – search i – insert a – append d – delete a – append d – delete r – replace e – exit s – search
This option will allow the user to search for a specified string in the worked-on string. If the string is
found, it will display the starting index (position) of the searched string in the worked-on string.
here is what i have so far.
#include <iostream> #include <cstring> using namespace std; int main() { char a_string[80];
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); }
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;
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");