| | |
count
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
When you read a string, increment a counter.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Mar 2006
Posts: 78
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Dave Sinkula
When you read a string, increment a counter.
C++ Syntax (Toggle Plain Text)
int main(void) { static const char filename[] = "input.txt"; FILE *file = fopen(filename, "r"); if ( file != NULL ) { char name[20]; int cnt=0; while (fscanf(file, &name) != "\n") { cnt++; } cout << cnt; fclose(file); } return 0; }
I'm having problems doing it...
Maybe tinker with this:
http://www.daniweb.com/code/snippet444.html
[edit]Or maybe this instead.
(Assuming this is still related to the configuration file stuff.)
http://www.daniweb.com/code/snippet444.html
[edit]Or maybe this instead.
#include <stdio.h>
int main(void)
{
static const char filename[] = "file.txt"; /* the name of a file to open */
FILE *file = fopen(filename, "r"); /* try to open the file */
if ( file != NULL )
{
char line[BUFSIZ]; /* space to read a line into */
while ( fgets(line, sizeof line, file) != NULL )
{
if ( line[0] != '#' && line[0] != '\n' )
{
const char *ptr = line;
char field [ 32 ];
int n, count = 0;
fputs(line, stdout);
while ( sscanf(ptr, "%31s%n", field, &n) == 1 )
{
printf("%d : \"%s\"\n", count, field);
ptr += n + 1;
++count;
}
}
}
}
return 0;
} Last edited by Dave Sinkula; Jun 8th, 2006 at 12:35 pm.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
•
•
Originally Posted by gampalu
Sorry to be boring but I want to count the number of strings only in the first line.
I mean a string each group of one or more caracters limited by a space...
Can you help me? I tried to use the code you indicated but without sucess...
C++ Syntax (Toggle Plain Text)
"Hello World This Is a String".
When learning to write C or C++ programs, it is important to also learn the correct terminology to avoid ambiguity.
Last edited by Ancient Dragon; Jun 8th, 2006 at 1:25 pm.
•
•
•
•
Originally Posted by gampalu
Sorry to be boring but I want to count the number of strings only in the first line.
I mean a string each group of one or more caracters limited by a space...
Can you help me? I tried to use the code you indicated but without sucess...
C++ Syntax (Toggle Plain Text)
# # The number of inputs for each epoch # Default value if omitted: 60 # InputNumber 60 # # The maximum epochs allowed in the network to converge # Default value if omitted: 300 # MaxEpochs 300 # # The number of neurons in the input layer # Default value if omitted: 19 # InputNeurons 19 # # The number of neurons in the hidden layer # Default value if omitted: 22 # HiddenNeurons 22 # # The number of neurons in the output layer # Default value if omitted: 1 # OutputNeurons 1 # # Default value if omitted: 0.01 # LearningRate 0.01 # # The dimension of each input # Default value if omitted: 48 # InputDim 48
C++ Syntax (Toggle Plain Text)
InputNumber 60 0 : "InputNumber" 1 : "60" MaxEpochs 300 0 : "MaxEpochs" 1 : "300" InputNeurons 19 0 : "InputNeurons" 1 : "19" HiddenNeurons 22 0 : "HiddenNeurons" 1 : "22" OutputNeurons 1 0 : "OutputNeurons" 1 : "1" LearningRate 0.01 0 : "LearningRate" 1 : "0.01" InputDim 48 0 : "InputDim" 1 : "48"
Last edited by Dave Sinkula; Jun 8th, 2006 at 1:34 pm.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- help with c program to count # of words in a string (C)
- Count number of checkboxes being checked in asp.net (ASP)
- derive full name of user and grep search count (Shell Scripting)
- word count (Java)
- resetting Window Xp mail count (Windows tips 'n' tweaks)
- I can't implement a word count into my text editor (JAVA) (Java)
- Counting post count (Growing an Online Community)
Other Threads in the C++ Forum
- Previous Thread: Complete shuffle of an array
- Next Thread: Help in C
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






