Hello funs2code! I have the following problem. I need to count the number of occurrences of a concrete word in a text file. I've tried to count the number of occurrences of each word at first. The following code has no errors but it isn't working! When I type in a command line "project1.exe test.dat cat dog cat dog" the empty string is showed. I've cheked if-statements -> right working. Then I've made a conclusion that problem is in for-statement (with iterators). Can anyone explain me, guys? #include <iostream.h> #include <fstream.h> #include <map.h> #include <string.h> #include <iterator.h> typedef std::map<std::string, int> …

Member Avatar
Member Avatar
+0 forum 5

So I have a code that prints out the `sys.argv` when the program is ran. How can I parse $ python ./arch.py install * to show `["./arch.py","install","*"]` Instead of `["./arch.py","install",#other files in directory]`?

Member Avatar
Member Avatar
+0 forum 1

This is a simple calcualtor program. What I don't understand is how I could modify it so that the calculation parameters could be intered from cmd. I don't understand how the argv and argc really work in this case. Do I need to replace all the ints with argv or something? #include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc, char *argv[]){ int num1, num2, result; char op; int check=0; do{ printf("Enter a calculation or press q to quit: "); scanf("%d%c%d", &num1, &op, &num2); if (op=='q'){ check = 1; return 0; } else{ if (op =='+') {result = num1+num2; printf("%d\n", …

Member Avatar
Member Avatar
+0 forum 4

i want to take the 1st argument from commandline, ie argv[1] and assign it to a `char target[80]` i know im making some very stupid beginer mistakes... but just cant understand what :( this is my code: #include <stdio.h> #include <string.h> void converge(char *targ, char *src); int main(char *argc[],char *argv[]) { char target[80]; target=(*argv[1]); converge(target, "This is a test of converge()."); printf("Final string: %s\n", target); printf("%s",argv[1]); return 0; } /* This function copies one string into another. It copies characters to both the ends, converging at the middle. */ void converge(char *targ, char *src) { int i, j; printf("%s\n", targ); …

Member Avatar
Member Avatar
+0 forum 2

Hi guys, I'm learning C and I still don't have some concepts very clear in my mind. I have to create a program that get the values from ARGV[] and puts into a vector: the program would work like that: ./program file1 file2 file3 My idea was to do something like: n=argc char command[argc] for(i<argv) { strcpy(command[i], argv[i+1]) } But I get a warning. I think I'm messing up the pointers, char, etc. What I imagine I'm doing with that code line is creating someting like... ARGV -------------> command [program] strcpy... [file1 ] [file1 ] [file2 ] [file2 ] [file3 …

Member Avatar
Member Avatar
+0 forum 5

I am trying to parse main(argc, argv[]); and i need to look at individual characters with in the strings pointed to by *argv[]. I though of a string as an array of chars. This builds fine but causes an error in execution. So what is a simple and straight forward way. Lets say I want to look at each character in a string pointed to by argv[c] and/or compare the each character or compare strings. I am sure this is quite simple and I want to keep it simple if possible. I am missing something here. Thanks in advance for …

Member Avatar
Member Avatar
+0 forum 4

Hey guys and gals, I'm just starting Python, and I was wondering if someone could translate this code into english ? from sys import argv script, first, second, third = argv print "The script is called:", script print "Your first variable is:", first print "your second variable is:", second print "Your third variable is:", third I got this code from the "Learn code the Hard Way" series, but I do not understand exactly what is going on... Thanks in advance :D

Member Avatar
Member Avatar
+0 forum 7

I have a project to have a file read using argc and argv. Then sort it and do some other things. I'm having trouble with the very first step. Loading the file. This is what I have so far. Any help you be great. [CODE] #include <stdio.h> #include <stdbool.h> void openFile(int argc, char *argv[]); int main(int argc, char *argv[]) { openFile(argc, argv); printf("\n\n"); return 0; } void openFile(int argc, char *argv[]) { int i; printf("\nThe number of arguments is %d", argc); printf("\nThe name of the program is %s", argv[0]); for ( i = 1; i < argc; i++) printf("\nUser value …

Member Avatar
Member Avatar
+0 forum 6

Dear All, I am very new to programming and really appreciate if you can help. I am using XCode as editor My code is below: [CODE] int main (int argc, char * const argv[]) { char a[10][25]; char *ptr_a; ptr_a = (char *)a[10][25]; for (int index = 1; index < argc; index++) { std::cout << index << " " << "The value in argv[index] is : " << argv[index]<< std:: strcpy(ptr_a,argv[index]); std::cout << index << " " << "the value of a at this point is : " << a << std::endl; } return 0; } [/CODE] After this when …

Member Avatar
Member Avatar
+0 forum 13

Some time ago, I was writing a small command line interpreter, with the help of [url=http://docs.python.org/library/cmd.html#module-cmd]the standard module cmd[/url] which offers minimal support for such tasks, and I had the problem that this module doesn't have a function to parse a command line to produce a list argv which can be passed to [url=http://docs.python.org/library/optparse.html#module-optparse]optparse[/url] for example. I found a first solution with the third party module [url=http://pygments.org/]pygments[/url] which contains parsers for different languages, and I parsed the command line using pygment's bash parser. However, I was not completely happy with this solution and I started looking for the C function …

Member Avatar
Member Avatar
+1 forum 1

The End.