C/C++ :: Grep Hanging For Standard Input

Mar 5, 2014

So I'm working on an assignment that is roughly about implementing the grep utility, only it has to be programmed in C. The weird nuance of the assignment is that while we are implementing the utility, we can use grep only we cannot pass grep a filename to search through(we are supposed to pipe a line from the file to standard input so that grep can examine it there.) Anyways, when I reach execlp, it will print out what is in stdin from the terminal, but it hangs at that point and I have to press Ctrl+Z to exit. I probably have the most difficulty with using this function, so I came up with a smaller scale model to get the basics down. Anyways, here's my code:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char* argv[]){

[Code] ....

View 10 Replies


ADVERTISEMENT

C :: Why Not The First Line At The Standard Input Read

Mar 21, 2013

Here's my code, it's for a poker hand evaluator

input:
'ad 2d 3d 4d 5d...
...4s 5s 6s 7s 8s'

I think it should go through all the 10 crads and disply the name of each card, but it seems to only do it for the second hand

Code:
include <stdio.h>
#include <ctype.h>
int main( void ) {
char inputtedhand[64];
int z=0, counter=0;
int index;
int i=0,m=0,n=0;

[Code].....

View 3 Replies View Related

C :: How To Signal End Of Standard Input Using Scanf

Oct 30, 2013

so i'm using scanf() this way

Code:

int i;
while (scanf("%i", &i))
printf("%i ", i);
printf("
done
");

i tried several combination of Ctrl+D and "Enter", it's not terminating, Ctrl+C just "cancels" the whole thing without printing "done", i'm running this on linux installed on a PC

View 9 Replies View Related

C/C++ :: Writing And Reading From Standard Input

Mar 18, 2015

I have an HTTP/1.0 webserver that I'm building in C that needs to exhibit CGI script functionality. Specifically, what I'm having trouble with is that I have two processes: process 1 is the webserver, process 2 is the CGI script. I fork in the webserver, and then call exec to run the CGI script (specifically, I used execv()). I've read from the CGI specifications in the RFC that in the case of a webserver receiving a POST request, the CGI script should read the arguments for the POST request from stdin. However, when I write to stdin, it simply echoes what was written to the terminal window and when the CGI script tries to read from stdin, it blocks.

So, with all that said, I'm pretty sure there is some simple conceptual explanation to my problem, but I can't figure it out. Do I need to use pipes or some form of interprocess communication to send the data from the webserver to the CGI script, or can it just be done with stdin (and possible stdout)?

View 2 Replies View Related

C :: Check To See If String From Standard Input Is Alphanumeric Or Not?

Dec 25, 2014

I'm trying to check to see if a string from standard input is alphanumeric or not. I feel as though there may be a function for this but...

Code:
for(test_pass = i; test_pass < i; i++){
if(test_pass[i] == ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'))
printf("Your password is alphanumeric!
");
}

The compiler wasn't too happy with this.

View 10 Replies View Related

C :: Using Scanf To Read A Character From Standard Input

Nov 1, 2013

So running the following code

Code:
#include <stdio.h>
int main(void) {
char c;
int i=1;
while (scanf("%c", &c)==1)
printf("loop sequence %i: %c(%i)

[Code] ......

Done it seems a "carriage return" serves two purposes here, one is to signal the program to read in the character typed in before the "carriage return", another serves as a second character typed, how can i do this cleanly, that is without having to use a "carriage return" as the second character to signal "I've typed in the first character already".

View 2 Replies View Related

C :: Accept Password From Standard Input And Goes Through All Possible Combinations Until It Matched

Dec 24, 2014

I've been experimenting a bit and can't find a decent way to make a brute forcing script that accepts a password from standard input, and goes through all possible combinations until it is matched. How to structure the code?

View 1 Replies View Related

C++ :: Read 100 Elements From Standard Input Device And Store Them In Array

Feb 19, 2014

Write code to do the following:

1) declare a variable ptr as a pointer to int and initialize it to NULL
2) dynamically allocate memory for an array of 100 elements
3) read 100 elements from the standard input device and store them in the array.

This is what I have so far, I'd like to know if its ok or if something is wrong.

int *ptr = NULL;
ptr = new int[100];
cin >> dataPtr [arr];

View 2 Replies View Related

C# :: WCF Duplex Service Callback Channel Hanging

Jul 1, 2014

I have an application based around a WCF Duplex service. I have problems when the user "Restarts" the work the application does... under the hood, the client side closes the connection to the WCF service and creates another. The Service contract is defined like so...

[ServiceContract(Namespace="net.tcp://namespace.MyService",
SessionMode=SessionMode.Required,
CallbackContract=typeof(IServiceCallback))]
public interface IMyService {
[OperationContract(IsOneWay=true)]

[Code] ....

The issue I see is that the _context.Close() call always times out and throws an exception. Although I'm then aborting the channel, this feels wrong to me, and I believe it's the cause of freezing in my application. Why the Close() call fails?

I missed something earlier regarding my callback implementation that might be relevant. It looks something like this:

[Callbackbehavior(ConcurrencyMode = ConcurrencyMode.Single,
UseSynchronizationContext = false,
IncludeExceptionDetailInFaults = true)]
public class CallbackImplementation : IServiceCallback {
public void SendMessage(string message){
// Do something with the message
} }

The exception message is "The ServiceHost close operation timed out after 00:00:30. This could be because a client failed to close a sessionful channel within the required time. The time allotted to this operation may have been a portion of a longer timeout.". There's no inner exception.

The big problem is that the client application freezes when the main application process is started after one client has been disposed and a new one created. I've also noticed that when you close the WPF application, it doesn't close properly and keeps running in the background, preveting you from starting a new instance.

View 1 Replies View Related

C :: Read Amount Of Order From Standard Input / Compute And Print Total Price After Discount

Apr 13, 2014

A Bookseller makes special discount for multiple orders of a book as follows:

AMOUNT and DISCOUNT as follows.

5-9 5% 10-14 10% 15-19 15% 20+ 20%

Write a C main function to read the amount of order from the standard input and compute and print the total price of the given order after the discount. Assume that unit price of a book is 10.00$

My problem is that.When i start with this

Code:
#include<stdio.h>
#include <stdlib.h>
int main(void)
{
int number;
float TotalPrice;
printf("enter a number:");

[Code] ....

I get 0 if i enter a number between 0 and 4(0 and 4 included). I don't know where I am doing a mistake. I also want to know if i can handle this buy just if statements. or how can i do it by while and for loops ?

View 1 Replies View Related

C++ :: Calculating Mean And Standard Deviation?

Oct 21, 2013

I've been trying to calculate the Second standard deviation but the average in the second loop isn't calculating correctly which is causing the standard deviation (method 2) to not calculate correctly. I can't find anything wrong.

Code:

#include <iostream>#include <iomanip>
#include <string>
#include <fstream>
#include <cmath>
usingnamespacestd;
int main ()

[Code]...

View 8 Replies View Related

C++ :: Calculate Standard Deviation

Jul 11, 2014

I have a program that will calculate max, average, etc from a file of numbers. However, I cannot get it to calculate standard deviation.

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>

[code]....

View 4 Replies View Related

C++ :: How To Make Standard Deck Of Cards

Feb 6, 2014

How to make a standard deck of cards and being able to shuffle and distribute the cards. I have made an array to store each card and I can display them but I assigned them all in order according to the suit and rank. Is this a viable way to do it if I intend to have a shuffle effect? Or should I create an array, randomly generate card, check for duplicates, then put them in the array, then display the array? Each card is a structure with two void pointer members for suit and rank.

View 1 Replies View Related

C :: Determine Compiler Version And Which Standard It Uses?

Jul 18, 2013

Is there any code I can use to determine my compiler version and which Standard It uses? I know the following code determine that my compiler followed ANSI But how about a version of that? ****My OS is now Ubuntu

Code:
#include <stdio.h>
int main(void){
printf("File :%s
", __FILE__ );
printf("ANSI :%d
", __STDC__ ); //return 1 if it follow ANSI but version?
return 0;
}

View 3 Replies View Related

C :: Date Math Using Standard Libraries?

Dec 22, 2013

Is there any way to do date math using standard C libraries? I looked around in the time.h but didn't see what I needed.

What I need to do is be able to add a certain number of minutes to a date and have it give the current date/time. For example, add 15918765 minutes to 01/01/1980 00:00 and have it tell me 04/07/2010 4:45PM. I really don't want to write this myself or go platform-specific.

Does this exist somewhere or am I SOL?

View 13 Replies View Related

C :: Translate Standard Code For Integers

Nov 14, 2013

I'm looking to translate say the standard code for 4 which is 52 to the integer 4 is that possible with a build in function i C?

View 5 Replies View Related

C :: Calculate Equations Just Like A Standard Calculator

Oct 23, 2013

The main point of the program is to calculate equations just like a standard calculator but I wanted to do it myself. I don't understand what the problem is right now but I've managed to create a program that asks for both values but somehow it doesn't want to ask for an operator (*, /, + etc). What's wrong with my code that the terminal skips the scanning part for the operator?

Code:

#include <stdio.h>
int main() {
int value1, value2, answer;
char operator;

[code]....

View 12 Replies View Related

C++ :: Standard Way To Add Version Number To Code?

Apr 15, 2014

Just wondering if there was a standard way people add a version number to their c++ code? I can just define a variable or #define and write the version number to that, but wanted to know if there is a standard method people use?

View 1 Replies View Related

C++ :: Looking For Standard Namespaces Inside Own Files

Sep 2, 2013

This has never happened before but I imagine that I've somehow accidently disabled a library or such.

namespace SB{
namespace Data{
class DLL Filed abstract{
//DLL is a macro defined as either __declspec(dllexport) or __declspec(dllimport)
//depending on whether this is open as a project or a header

[Code]....

The error is from intellisense and is present on every occurrence of std::string

View 14 Replies View Related

C++ :: Calculating Standard Deviation From File

Mar 21, 2014

Here's my attempt:

input.open(name);
if (input.fail()){
cout <<"Error opening file"<<endl;
}
while (input>>numbers)
{
counter++;
total += numbers;

[Code]...

Copy of the output:

Error opening file
The Standard Deviation of all the numbers is: -9.25596e+061
Press any key to continue . . .

Its not giving me the right answer.

View 1 Replies View Related

C++ :: Standard Way Of Changing The Text And Colour

Oct 7, 2014

Earlier 4-5 years back, When I started learning C++ I used textcolor() function to change the textcolour. But its not working in Code Blocks 13.12. Is there any other standard way to color the text and background.

View 2 Replies View Related

C++ :: Unable To Compute Standard Deviation?

Mar 15, 2014

Unable to compute Standard Deviation

View 1 Replies View Related

C++ :: Output Correct Standard Deviation

Feb 1, 2015

The program does compile the average and the mean correctly. I can't understand why the standard_deviation member function isn't applying the sqrt properly:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const int N = 10;
class Standard_Deviation {

[Code] ....

View 7 Replies View Related

C Sharp :: ISO 8601 To Standard Date

May 2, 2013

How I can convert an ISO 8601 to a standard DateTime like dd/mm/yyyy.

The string is:
2013-01-03T00:00:00.0000000Z

And I'd want it to show it like so:
03-01-2013

I'm storing this in an SQLite Database and the code I use to store everything:

conn.Open();  
                  command.Connection = conn;
                  command.CommandText = "insert into Test ([Date], [LogName], [Channel], [DateRecord], [SizeInBytes]) values" 
+ "(@Date, @LogName, @Channel, @DateRecord, @SizeInBytes)";  
                                command.Parameters.Add("@Date", DbType.String);
                                command.Parameters.Add("@LogName", DbType.String);
  
[Code] ....

the Visual aspect is that I use a datagridview to see the data, so the conversion would have to happen while I read and store the data in the database.

View 4 Replies View Related

C++ :: How To Parse XML File With Standard Library

Mar 11, 2015

How can I parse an .xml file with just C++ Standard Library?

View 14 Replies View Related

C++ :: Class Military To Standard Time

Feb 22, 2012

basically my program lets the user inputs military time( in hour, minute, and seconds). I need to convert this to standard time and have am/pm at the end. Here is what I have so far.

I have a 3 files, time.h, time.cpp (defines functions), and main.cpp (testing). I have a problem in my main function under main.cpp. I don't understand how to set the parameters of the two time objects; t and test. When i do test( hr, min, sec) it shows random numbers when it prints out in standard time.

(HEADER FILE called Time.h)

#ifndef TIME_H
#define TIME_H
class Time
{

[Code].....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved