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:
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
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)?
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".
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?
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];
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.
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 ?
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 ()
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.
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; }
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.
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;
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?
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
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.
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 {
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.
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.