C :: Program That Does UNIX Strings
Jun 4, 2014
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.
View 2 Replies
ADVERTISEMENT
Dec 11, 2013
I have written a program which uses a pid to check if the process is currently running and return a value based on the system call result.But the program core dumps
Code:
#include <stdio.h>
#include <string.h
int main( argc, argv )
int argc;
char * argv[];
{
int p_pid = 99;
char buff[1000];
}
[code]....
What is the mistake in this code and is it portable in both unix/linux , is the method secure (grepping for program name )?
View 6 Replies
View Related
Aug 15, 2013
trying to convert some C++ code written for LINUX/MAC to run on windows. I think signal handling is not as developed for Windows but the error I am getting is that the struct I am trying to use is undefined. I have #include <csignal> at the top and the line giving the problem simply says "struct signal act;". Any pointers or is signal a LINUX native command?
View 2 Replies
View Related
Sep 1, 2014
I am converting unix timestamp to datetime format like this:
static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
static readonly double MaxUnixSeconds = (DateTime.MaxValue - UnixEpoch).TotalSeconds;
public static DateTime UnixTimeStampToDateTime(double unixTimeStamp) {
return unixTimeStamp > MaxUnixSeconds
? UnixEpoch.AddMilliseconds(unixTimeStamp)
: UnixEpoch.AddSeconds(unixTimeStamp);
}
use it:
Console.WriteLine("From UNIX do datetime 1300123800440 : " + UnixTimeStampToDateTime(1300123800440));
output: 14.03.2011 5:30 PM
Now i would like to have function which convert it back to unix timestamp but unfortuently my new function is cutting down last 3 digits for instance:
public static long UnixTimestampFromDateTime(DateTime date) {
long unixTimestamp = date.Ticks - new DateTime(1970, 1, 1).Ticks;
unixTimestamp /= TimeSpan.TicksPerSecond;
return unixTimestamp;
}
after use of it i am retrieving:
Console.WriteLine(UnixTimestampFromDateTime(Convert.ToDateTime("14.03.2011 5:30 PM")));
result:
1300123800
View 14 Replies
View Related
Oct 28, 2014
Below is my sample code of a C program. I am doing lot of processing, but my issue is I am getting a segmentation fault error in my main when I am putting the file names at the command line and using them. The program works great in Windows, but its giving error in Unix.
Below is the code of my Main function.
Code:
int main(int argc, char *argv[])
{
FILE *user, *requests;
char c;
user = fopen(argv[1], "r");
requests = fopen(argv[2], "r");
//For users
struct userStorage *USHead = NULL;
//struct users *userHead = NULL;
[Code]...
View 6 Replies
View Related
Mar 3, 2013
How can we debug the multithreaded application in unix environment?
View 1 Replies
View Related
Mar 18, 2015
I have been trying for several months to create a simple SNTP single Client/Server based on RFC5905. Finally I manage to make it work at least I think it works correctly, but when I tried to test my code against a real NTP server (e.g. 0.se.pool.ntp.org:123) the timestamps that I am receiving need to be recalculated. I have tried several different approaches but no matter for 3 days now but no matter what I tried nothing yet.
The problem that I am having in not so much programming error is more about knowing how the NTP server operates.
How to convert the NTP timestamp to Unix epoch timestamp?
Syntax to execute the Server e.g. ./server 127.0.0.1:5000 and Client e.g. ./client 127.0.0.1:5000
Syntax to execute the Client against a real NTP server e.g. ./client 0.se.pool.ntp.org:123
Sample of working code Client:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
[code]....
Sample of printed output when I use Server and Client.
Reference Identifier 0 LOCL
Reference Timestamp 0.0 1426637081.3564398733
Originate Timestamp 1426637087.3570333925 1426637087.3570333925
Receive Timestamp 1426637087.3570334078 1426637087.3570334003
Transmit Timestamp 1426637087.3570333925 1426637087.3570334046
Sample of printed output when I am probing a real NTP server (e.g. 0.se.pool.ntp.org:123).
Reference Identifier 0 $
Reference Timestamp 0.0 3879449560.3503094062
Originate Timestamp 1426637090.3573978972 1426637090.3573978972
Receive Timestamp 1426637090.3573992772 2722083800.781009125
Transmit Timestamp 1426637090.3573978972 2722083800.937312997
View 2 Replies
View Related
Mar 8, 2012
I am trying to write a client/server application that takes input to an array of structures from the user,stores the data in a shared memory segment and then writes the same to a file when I close the application. How do I get started? And how do I ensure that the server stores the data correctly? Also, the server needs to be a concurrent server that accepts connections from multiple clients.
View 1 Replies
View Related
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
}
[code]....
View 2 Replies
View Related
Oct 16, 2013
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.
Code:
#include<stdio.h>
main()
{
char str1[] = "hello" ;
char str2[]= "hello" ;
int q;
q = xstrcmp(str1,str2);
printf("%d",q);
}
[code]....
View 5 Replies
View Related
Oct 11, 2013
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!
View 1 Replies
View Related
Jan 18, 2015
I can't seem to get my program to alphabetize a vector string. It displays the names, but not in a sorted order.
void sort_names(vector<string> &nameList) {
int i, minIndex;
string minValue;
int size;
size = nameList.size();
[Code] ....
View 4 Replies
View Related
Oct 6, 2014
Any simple program that uses tolower to convert strings into lowercase? Or simply just the general syntax of tolower pls. Can find it in google.
View 5 Replies
View Related
Sep 2, 2013
'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;
}
[code]....
View 3 Replies
View Related
Jun 20, 2013
I am having difficulty with class objects.
1. why my program won't actually compare the two strings.
2. why and where I am having a memory dump crash.
The following is my main.cpp, String.cpp, and the header file in that order.
#include <iostream>
using namespace std;
#include "GREEN_String.h"
void main () {
GREEN_StringStr1;
GREEN_StringStr2 ("AdrianGreen");
[Code] .....
View 5 Replies
View Related
Nov 22, 2014
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.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"string_utils.h"
int strContains(const char * str,const char * subStr) {
[Code] ....
View 5 Replies
View Related
Sep 29, 2013
How to write a programme that take strings from file and push it into the stack with number of each sting string before it and later clean the stack?
View 6 Replies
View Related
Oct 18, 2014
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];
[Code] .....
View 4 Replies
View Related
Apr 7, 2013
I am programming a translator, and I have it so that it detects words with spaces both in front of and behind them, so I did "string.append(space);" where space equals " ". That added a space to the end, but I still need a space added to the front.
View 1 Replies
View Related
Feb 12, 2014
I have a problem who must print the sentences who have lenght more than 20 characters. I dont know why, but it prints just the first words. Look what i made.
#include<stdio.h>
#include<conio.h>
int main()
[Code]....
For instance :
Give the number of sentences : 3
First sentence : I like the website bytes.com
Second sentence : I like more the website bytes.com
Third sentence : bytes.com
After I compile the program it should print the first two sentences.
View 2 Replies
View Related
Nov 16, 2013
I tried to add 2 or more strings together but failed.
eg I would like to add "KK" & "LL" together by adding but it couldn't work.
string string_B = "KK";
string string_C = "LL";
string_A = string_B + string_C;
View 2 Replies
View Related
Mar 5, 2013
1. I finished reading a beginning C book, and in the section about arrays, it says that one string can fit in a character array (char arrayname[]) but there cannot be a string array (string arrayname[]) that have multiple strings. Is
Code: string arrayname[4] = {"one", "two", "three"}; not valid?
My compiler lets me run it and it works, but why is the book saying it's wrong?
2. I know you can represent multiple strings in a character array by:
Code: char newarray[10][4] = ("one", "two", "three");
because [10][4] indicates that there should be four newarrays created with a max of 10 characters each, but is
Code: string multiplestrings[10][4] = ("i love you", "hello come to me", "i don't get C"; "hello world", "what are arrays"; "i am happy", "I am learning how to code"); valid?
Does multiplestrings[10][4] basically create 4 string arrays that have a maximum of 10 different strings within each string array?
View 6 Replies
View Related
Dec 14, 2014
How join two strings? basic reason is add given filename little text to end. I try do by hobby not school project program which converts files format x to format y.i dont say which formats becouse reading and writing is almost done. (only little amount code is needed).'
View 2 Replies
View Related
Feb 9, 2015
javascript:tx('quote')
void family () {
string father;
string mother;
string kids;
int x;
int y=0;
[Code] .....
How am I allowed to but the 3 strings father, mother and kids in a array?
View 3 Replies
View Related
Mar 26, 2014
None of my string is coming out onto my output file..
void OutputHeading (ofstream& fout, string CLASS_EXERCISE,
string PROGRAMMERS_NAME);
void OutputDivider (ofstream& fout, int WIDTH,
char symbol);
void OpenFiles (ofstream& fout, ifstream& fin);
[Code] .....
View 1 Replies
View Related
Jul 3, 2013
I've got a very simple but annoying problem.
if (letter3=="
"){
letter3==letter;
PrintCharacterLineEnd();
This is a code. the string "letter3" contains the string "
". What I want to happen is when, letter3 contains the text "
" I want to go to the function PrintCharacterLineEnd.
However, as of right now it's not working.
View 14 Replies
View Related