|
Firstly you cannot just store a string to an array, it needs to be copied from FindFileData.cFileName to some memory buffer, in order to use it later in the program. Secondly you have not allocated any space to your array so you cannot store anything in it. Thirdly your array is of the wrong type; but you knew that because the compiler told you.
I would suggest working through some basic C++ examples of using different types and arrays before tackling such an advanced project as this.
|
|
|
|
|
Hi Richard MacCutchan,
can you please suggest me what type of data type i should use?can i store the output from FindFirstFile() and FindNextFile() in an array?
|
|
|
|
|
ravi 12 wrote: can you please suggest me what type of data type i should use?
Well you need an array of strings, or more correctly char pointers, each of which needs to be initialised to point to a buffer large enough to hold the path name returned by FindNextFile() . Then you need to copy the returned path name into the next free item in the array, and continue your loop. however you still don't know how many items you will need to store, so you also need a mechanism for expanding your array.
As I suggested in my previous post, you should spend some time getting to know arrays of simple and complex types before trying this program.
|
|
|
|
|
Hi,
I want to store the output from FindFirstFile() and FindNextFile() function in an array.
Is there any way to store the output of FindFirstFile() and FindNextFile() in an array?please suggest me.
|
|
|
|
|
inputs any set integer from 1 to 3999 and separated by a comma then separates it then gets its average.
Example:
input: 1,2,3,8,4,6
compute its average
1+2+3+8+4+6=24
24/6=4
Output:4
...pls help
|
|
|
|
|
Tabang wrote: ...pls help
Well in this half of the universe 24/6 = 4!
|
|
|
|
|
Tabang wrote: ...pls help
With what? You have a multi-step problem here. You could start with:
#include <string>
#include <iostream>
void main( void )
{
std::string strInput;
cout << "Input: ";
cin >> strInput;
}
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: std::string strInput;
I'm pretty sure that wouldn't work with Turbo C[^]
|
|
|
|
|
Details, details.
On an unrelated note, it's been 19 years since I used Turbo C. That was a fun product.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Oh, I'm pretty sure David can do that with Turbo C .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
pls help me with the separation of commas from the set of numbers ...its hard
|
|
|
|
|
i guess... pls help me separate the commas from the numbers so i can calculate the average... it hard to separate it when im just a bigginer.. pls
|
|
|
|
|
Thanks. your codes are c++ i think?
|
|
|
|
|
It's not their fault. Actually, the people here are such experts that they can write a turbo c compiler in less time than what it would take for them to figure out if cout/cin or std::string is a C-language feature or not. They have risen much higher than the realms of specific programming languages. They only understand the language of bits and bytes and in their mind, both string and char are just a piece of f* memory holding some bits.
|
|
|
|
|
And what's your trouble about?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I know what you want. Just tell me if I am correct.
int main(void)
{
int a,b,c;
scanf("%d,%d,%d",&a, &b, &c);
printf("\nYou just entered: %d, %d, %d", a, b, c);
}
Pay special attention to the commas used inside the scanf function. I think it addresses your doubt to some extent. I had this doubt all my life.
Second, I suppose you will say that above program is very rigid as it allows input of only 3 variables. What if the no. of variables is not known.
Very valid question, I say. Only I have forgotten how to work with console and it give me creeps to find out about gets etc. See this [^]
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main(void)
{
char input[255];
int sum = 0;
int num = 0;
gets(input);
char* token;
token = strtok(input, ",");
while (token != NULL)
{
sum += atoi(token);
++ num;
token = strtok(NULL, ",");
}
printf("\nSum = %d, average = %f\n", sum, (num==0? 0 : (float)sum/num));
return 0;
}
Hope it helps?
|
|
|
|
|
THANK YOU SO MUCH.. it really helpes...cool...
|
|
|
|
|
(num==0? 0 : (float)sum/num)
what does this code do?..... is there any other alternative in finding the average i mean other formula..pls reply
|
|
|
|
|
Can you tell what is the conditional or ternary operator [? :] in C and how does it work? Any example that can help me in understanding it?
Answer my question and i will answer yours.
|
|
|
|
|
can anyone help me on this code. im trying to input a hindu arabic number in a text file input.txt then it will output a conversion of that number into roman numeral... but the problem is it wont output the convertion.. the out put are trash characters.... but this worked when i was not inputting in a notepad .it worked when i was inputting in the running turbo c... here are my codes...... the first one is when the inputs are still in c and the other is in a .txt file....
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
FILE *fp;
int a;
char base[2];
int i,x;
char str[50];
char c;
int counter=0;
do
{
clrscr();
if(counter!=0)
{
for(i=0;str[i]!=NULL;i++)
str[i]=' ';
}
printf("\nEnter a number from 1 to 3999 only: ");
scanf("%d",&a);
fp = fopen("c:\output.txt","a+");
fprintf(fp,"\n\nHindu Arabic: %d",a);
if(a<=0 || a>=4000)
{
printf("out of range");
fprintf(fp,"\t\tOut of range!!!!");
goto exit;
}
i=0;
while(a!=0)
{
if(a>=1 && a<4)
{
base[0] = 'I'; base[1] = ' ' ; a = a-1;
}
else if(a>=4 && a<5)
{
base[0] = 'I'; base[1] = 'V'; a = a-4;
}
else if(a>=5 && a<9)
{
base[0] = 'V'; base[1] = ' '; a = a-5;
}
else if(a>=9 && a<10)
{
base[0] = 'I'; base[1] = 'X'; a = a-9;
}
else if(a>=10 && a<40)
{
base[0] = 'X'; base[1] = ' '; a = a-10;
}
else if(a>=40 && a<50)
{
base[0] = 'X'; base[1] = 'L'; a = a-40;
}
else if(a>=50 && a<90)
{
base[0] = 'L'; base[1] = ' '; a = a-50;
}
else if(a>=90 && a<100)
{
base[0] = 'X'; base[1] = 'C'; a = a-90;
}
else if(a>=100 && a<400)
{
base[0] = 'C'; base[1] = ' '; a = a-100;
}
else if(a>=400 && a<500)
{
base[0] = 'C'; base[1] = 'D'; a = a-400;
}
else if(a>=500 && a<900)
{
base[0] = 'D'; base[1] = ' '; a = a-500;
}
else if(a>=900 && a<1000)
{
base[0] = 'C'; base[1] = 'M'; a = a-900;
}
else if(a>=1000 && a<4000)
{
base[0] = 'M'; base[1] = ' '; a = a-1000;
}
else
{
base[0] = ' '; base[1] = ' ';
}
str[i]=base[0];
str[i+1]=base[1];
i+=2;
}
printf("\n\n\nThe number converted into roman numerals is: ");
fprintf(fp,"\t\tRoman Numeral:");
for(i=0;str[i]!=NULL;i++)
{
if(str[i]!=';' && str[i]!=' ')
printf("%c",str[i]);
fprintf(fp,"%c",str[i]);
}
exit:
printf("\n\n\n\nPress any key to continue or space to exit... ");
fclose(fp);
c = getch();
counter++;
}while(c!=' ');
}
heres the one that inputs in a notepad and is not working
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
FILE *fp,*fp2;
int a;
char base[2];
int i,x;
char str[50];
char c;
int counter=0;
do
{
clrscr();
if(counter!=0)
{
for(i=0;str[i]!=NULL;i++)
str[i]=' ';
}
fp = fopen("c:\output.txt","a+");
fp2= fopen("c:\input.text","r");
while(!feof(fp)){
i=0;
fscanf(fp2,"%d",&a);
if(a>=0 && a<=3999)
{
fscanf(fp2,"%d",&a);
if(a>=1 && a<4)
{
base[0] = 'I'; base[1] = ' ' ; a = a-1;
}
else if(a>=4 && a<5)
{
base[0] = 'I'; base[1] = 'V'; a = a-4;
}
else if(a>=5 && a<9)
{
base[0] = 'V'; base[1] = ' '; a = a-5;
}
else if(a>=9 && a<10)
{
base[0] = 'I'; base[1] = 'X'; a = a-9;
}
else if(a>=10 && a<40)
{
base[0] = 'X'; base[1] = ' '; a = a-10;
}
else if(a>=40 && a<50)
{
base[0] = 'X'; base[1] = 'L'; a = a-40;}
else if(a>=50 && a<90)
{
base[0] = 'L'; base[1] = ' '; a = a-50;
}
else if(a>=90 && a<100)
{
base[0] = 'X'; base[1] = 'C'; a = a-90;
}
else if(a>=100 && a<400)
{
base[0] = 'C'; base[1] = ' '; a = a-100;
}
else if(a>=400 && a<500)
{
base[0] = 'C'; base[1] = 'D'; a = a-400;
}
else if(a>=500 && a<900)
{
base[0] = 'D'; base[1] = ' '; a = a-500;
}
else if(a>=900 && a<1000)
{
base[0] = 'C'; base[1] = 'M'; a = a-900;
}
else if(a>=1000 && a<4000)
{
base[0] = 'M'; base[1] = ' '; a = a-1000;
}
else { base[0] = ' '; base[1] = ' '; }
str[i]=base[0];
str[i+1]=base[1];
i+=2;
}
fprintf(fp,"\nRoman Numeral:");
for(i=0;str[i]!=NULL;i++)
{
if(str[i]!=';' && str[i]!=' ')
printf("%c",str[i]);
fprintf(fp,"%c",str[i]);
}goto exit;
}
exit:
printf("\n\n\n\nPress any key to continue or space to exit..");
fclose(fp);
c = getch();
counter++;
}while(c!=' ');
}
please can anyone help?
|
|
|
|
|
Tabang wrote: please can anyone help?
So when you step through this code using the debugger (you are doing that, aren't you?), what do you see?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
No surprise, since the latter program is a bad porting of the former one. Try
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
FILE *fp, *fpi;
int a;
char base[2];
int i,x;
char str[50];
char c;
int counter=0;
fpi = fopen("input.txt","r");
fp = fopen("output.txt","a+");
if (!fp || !fpi) return;
while (!feof(fp))
{
if(counter!=0)
{
for(i=0;str[i]!=NULL;i++)
str[i]=' ';
}
if (fscanf(fpi, "%d",&a) != 1) break;
fprintf(fp,"\n\nHindu Arabic: %d",a);
if(a<=0 || a>=4000)
{
printf("out of range");
fprintf(fp,"\t\tOut of range!!!!");
goto exit;
}
i=0;
while(a>0)
{
if(a>=1 && a<4)
{
base[0] = 'I'; base[1] = ' ' ; a = a-1;
}
else if(a>=4 && a<5)
{
base[0] = 'I'; base[1] = 'V'; a = a-4;
}
else if(a>=5 && a<9)
{
base[0] = 'V'; base[1] = ' '; a = a-5;
}
else if(a>=9 && a<10)
{
base[0] = 'I'; base[1] = 'X'; a = a-9;
}
else if(a>=10 && a<40)
{
base[0] = 'X'; base[1] = ' '; a = a-10;
}
else if(a>=40 && a<50)
{
base[0] = 'X'; base[1] = 'L'; a = a-40;
}
else if(a>=50 && a<90)
{
base[0] = 'L'; base[1] = ' '; a = a-50;
}
else if(a>=90 && a<100)
{
base[0] = 'X'; base[1] = 'C'; a = a-90;
}
else if(a>=100 && a<400)
{
base[0] = 'C'; base[1] = ' '; a = a-100;
}
else if(a>=400 && a<500)
{
base[0] = 'C'; base[1] = 'D'; a = a-400;
}
else if(a>=500 && a<900)
{
base[0] = 'D'; base[1] = ' '; a = a-500;
}
else if(a>=900 && a<1000)
{
base[0] = 'C'; base[1] = 'M'; a = a-900;
}
else if(a>=1000 && a<4000)
{
base[0] = 'M'; base[1] = ' '; a = a-1000;
}
else
{
base[0] = ' '; base[1] = ' ';
}
str[i]=base[0];
str[i+1]=base[1];
i+=2;
}
str[i]='\0';
fprintf(fp,"\t\tRoman Numeral:");
for(i=0;str[i]!='\0';i++)
{
if ( str[i] != ' ')
{
fprintf(fp,"%c",str[i]);
}
}
exit:
counter++;
}
fclose(fp);
fclose(fpi);
}
BTW: In both programs you missed to zero-terminate the string str .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Friday, October 9, 2009 6:16 PM
|
|
|
|
|
thanks so much for that, but the c would become assigned and not used... what should be done?
|
|
|
|
|
thanks so much for that ops it worked i erased the do statement...sorry about that.....Thanks..... what should i do i the input of that one will be a set off numbers and separater by comma?... and the average of that set number will be that one that is converted into Roman numerals?
pls help
|
|
|
|
|
Hi,
I have a class that handle .html files but the file that came to me is a .doc, so, i whould like to convert it to .html
There´s a .dll or .exe or classes for compiling ?
Tanks for your help.
|
|
|
|