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

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

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

The End.