Hey Dream2Code, read this:
http://www.gidnetwork.com/b-58.html
yellowSnow commented: Nice explanation of byte. +1
Salem commented: Excellent :) +36
Remove this line from your code (if you don't make use of the Allegro library): #include <allegro.h>
Or if you're using Allegro:
If I'm not wrong each Allegro program looks like:
#include <allegro.h>
int main()
{
allegro_init();
/* more stuff goes here */
return 0;
}
[B]END_OF_MAIN()[/B]
So you'll have to add the END_OF_MAIN()
line, be sure you link the library as well.
>I can't make any sense of the OP's question?
Well, I'm not sure what he's trying to do (as he didn't provide an illustrating example).
I think he wants to convert a 'readable' string to a string containing each character's hexadecimal equivalent, but the string he's trying to use in his 'example' is not big enough for that.
An example of what I think he wants to do:
string to convert: "abcdef"
converted string: "616263646566"
Well, try this one:
wordRecord test; [B]// (1)[/B]
sc.printDict(test);
(1): You can put struct at the beginning of this line, but this isn't obligated in C++.
Just an easy example:
String[] digits = {"", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine"};
int number = 5;
System.out.println( digits[number] );
I hope you notice the big advantage of doing it this way :)
Analog to this, create arrays for the tens, etc.
But don't put numbers like 25 in the array, as you can create it's string representation by just combining "twenty" and "five".
It's just impossible to hard-code the text-representation for every number in your code, it will take you hours of typing work, unless you simply use arrays and create the numbers by just combining and putting together the base numbers from which you can derive and build every number.
You would better make use of arrays to avoid such huge switches.
> string ss="this is an encrytpion program";
Could it be that you meant: char ss[] = "this is an encrytpion program";
here?
Otherwise please clarify.
The program pretty much is not running at all....every time i try to compile it gives me an error related to an undeclared variable that has already been declared in typedef.
Can you also post all the errors you're having?
>I am having a hard time writing a program to do the following.........
Please tell us where you're having problems with.
An addition for the OP:
Also ensure that the variable newSize is of type size_t.
Strings don't have negative lengths, so using int isn't the best option here (because it's signed, this means that it can hold negative values).
I don't see any mistake in your code, it works fine with me.
Ensure that the file you're trying to open exists.
But...
Technically this line displays incorrect information: cout<<endl<<"File Not Found";
It's not because the file couldn't be opened, that the file automatically doesn't exist.
For example it could be that you try to open an existing file, but this fails because of certain circumstances, then the file exists, and you display "File not found"
.
Most of Windows was written in C. You might or might not think that is marvellous.
Please don't bring him on the idea to create his own OS :P
How about reversing in place..............
Yes, but you'll need a closing curly brace (on the last line) in order to make the code compile :P
Thanx for response, please write the program in core java.
Do you imply that I have to write the program?
There's one obstacle in your way:
We only give homework help to those who show effort!
So please let us know when you're finished.
Edit::
please help me in writing a program in java.........
I think you don't get the dividing line between helping and giving free code (the whole program) to you.
Well, you just posted your assignment.
Is there any code you wrote to follow?
What do you have now?
I guess you wanted to write this:for (i = 0; *(ptr+i) [B][COLOR="Green"]!=[/COLOR][/B] '\0'; i++)[COLOR="Green"][B];[/B][/COLOR]
(also note the semicolon at the end)
And this won't work either if you want to place a '-' at the end of the name:*ptr = '-';
.
I guess you wanted to write: *(ptr+i) = '-';
here.
And you'll also want to add this line: *(ptr+i+1) = '\0';
right after it (because you overwrite the null-terminator with the previous line).
And you'll also want to change this:printf("\n\n%s", ptr[i]);
to this:printf("\n\n%s", ptr);
or better, to this:printf("\n\n%s", name);
Remark: make sure that the string which will hold the name is big enough, maybe change its size to 20?
Why do you use a separate variable? If you could just increment the pointer?
Also: please post your code using code tags the next time
Edit:: I assumed that you wanted to place a '-' at the end of the string.
Edit:: Please mention the next time also what your code has to do as it will make life easier for both: you and me.
12-bit bytes exist?or its a joke?
Nope, not a joke.
It's just: most of the time the word 'byte' is interpreted as an octet of bits (8 bits), but this is not fully correct, as a byte is an abstract term for the smallest addressable unit for your system.
If the smallest addressable unit is 12 bits on a certain system, then a byte on that particular system consists out of 12 bits.
>and in one byte maximum of 256 disticnt values can be generated
But...but... This doesn't apply to 12-bit bytes :P
Irony is a beautiful thing :)
>can who suggest me for c mini project ....
Yes, do a forum search. (it will give you plenty of ideas)
>u can also give source code .....
No, you'll have to write that yourself.
Are you referring to me...??? Just take it easy ok. Thanks
No, I think he's referring to the pope :P
It are just the forum rules, I didn't invent them, but I agree with them.
If you have problems, you should just post the code you have so far, together with a detailed explanation of what your program does, and a description about what problem you have, and then, we can help you.
But we here have no time to write code for no matter who.
As an char takes 1 byte*(8 bits) in memory so it cant store only 256
distinct binary values (2^8).
A char is one byte, but that doesn't make that it has always 8 bits, there are also machines where a byte consists of 6 bits for example.
If you want to get the number of bits for a char 'object', then you can use the CHAR_BIT macro, as defined in limits.h.
A byte is just an abstract term for the smallest addressable unit of your system.
The ASCII character set is technically a 7-bit character set, which means that it can only hold 2^7 = 128 characters portably.
However, there are several extensions to the ASCII character set, which extend it to use a full eight bit range, the upper range is not portable because it can produce different output on different systems (which for instance use different code page settings).
Please...its not an assignment for me. Its for a friend. I need an assistance thats why i posted it.
ROFLMAO, The best one I've heard in a while :)
Do you know others like this?
If you are such a benefactor, would you mind doing my homework too?
>>function is platform dependent:
yes it is.But
You intrepreted the thing wrongly.
it will always return an integer but its intrepretation is system dependent.
means,
in some systems 0 means success some other 1 means success.like that.
>>returning an int value, whose interpretation is system-dependent.it means it will always return an int , we have intrepret its success of failure according to systems.
Yes, but then your code snippet won't run on every system.
That's what I meant.
dont use a char * to capture the return of system.
****system() will always return the exit status which is an integer.
use like:int status; status=system("command"); if(status!=0) { printf("system command not executed properly"); }
apart from this everything else is fine.
The return value of the system() function is platform dependent:
http://www.cplusplus.com/reference/clibrary/cstdlib/system/
>Please do email me d code....n thanks for your assistance.
Do you really think the people here at this forum are here to do your homework?
We've better things to do.
http://www.daniweb.com/forums/thread78223.html
http://www.daniweb.com/forums/announcement8-2.html
You always have to pay attention when you create a vector of pointers, consider this:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int*> myvec(5);
if( 5 > 3 )
{
int a = 35;
myvec[0] = &a;
cout << *myvec[0] << endl;
}
cout << *myvec[0] << endl; // not guaranteed to print 35 on the screen
return 0;
}
When variable a goes out-of-scope, then the first pointer in vector myvec (myvec[0]) will point to some memory location which doesn't belong to your program anymore.
Try removing recently installed hardware and software.
Try System Restore.
This thread is already about 2 years old, and you're still replying in it.
If someone wants to read a good book about C++, then he can check out the sticky about that.
Maybe for further interest: ___________.
You want to act your program like this, right?
how many Fibonacci number you need? : 10
how many sequence: 3
21 34 55
Keep track of the amount of numbers already generated, when this amount exceeds [I]the_amount_of_fibonacci_numbers_you_need[/I] - [I]sequence[/I]
, you start printing the numbers.
(In this case you would start printing the numbers at the moment when the generated fibonacci number exceeds 7 (10-3)).
> s = system("sha1sum -t a.txt");
system() doesn't return the output of an executed command.
It returns an integer value, which indicates whether it could execute the command successfully or not.
Edit:: Dream2Code posted before me.
>You mean to say,if my main string is 1024 chars long.
I need to loop for 1024 times.
No, you'll have to break the loop when strstr() returns NULL, to avoid additional overhead.
To avoid other overhead, you could increase the pointer with the length of the substring you're searching for.
Internally the strstr() function also loops through the string, at the moment when it finds the substring, it stops right there, without looping through the rest of the string, if it hasn't found the substring, the function will have looped through the whole string, and it will return NULL.
When it has found the substring, it will return a pointer to the beginning of that substring.
Steps 2 and 4 indicate that you'll have to use a loop.
Well, if you first skip all non-alphabetic characters, using a loop, then the loop will stop when the first letter of the word is encountered.
And then he'll have to run another loop, to get to the end of the word.
Edit:: So my first post was not correct.
1)read the string charecter wise (one char at a time) until you find a space.
here is your word.
Won't work if the string starts with spaces, what about a string like this: " firstword"
.
However, it will work if you first skip all whitespaces.
Interesting info about rand():
http://www.eternallyconfuzzled.com/arts/jsw_art_rand.aspx
Some code snippets:
http://www.daniweb.com/code/snippet1019.html
http://www.daniweb.com/code/snippet1034.html
http://www.daniweb.com/code/snippet1179.html
Don't use EOF as an exit indicator for your loop, instead read a file like this:
while ( getline(infile, line2) )
{
// Do stuff with the read data
}
How would u determine the end of a word using pointers?
Here's an approach:
>The code was just a normal......
Would you mind posting the whole program please?
>Has someone encountered this problem before?
>Would someone make a suggestion regarding how solve this problem?
Uhm...You could maybe let your program throw an error when it wasn't able to get data from the three columns, if the data is incomplete, your program cannot work with it so I guess that would be a good solution.
(But you'll have to keep track of the number of read values in order to know that).
Or...
Assume your file looks like this:
[I]col1[/I] [I]col2[/I] [I]col3[/I]
hello world
Then we can use the following approach to achieve what you want:
I assume that you'll read these values into an array first, I'll call this array 'temp', you'll also need a counter in order to keep track of the number of values read, I'll call this variable 'count'.
So to begin, you read all the values on that line into array 'temp'.
(Each time you read a value, you increase variable 'count' with one)
After reading the first line from the file, the array will look like:
[0] = "hello";
[1] = "world";
( [3] = ?; )
The annoying thing is that these values aren't in the order we want it, so let's create an array where the values are in the right order, I'll call this array 'columns'.
All the information we've got about the columns is these:
Number of columns in the file: 3 (probably a constant within …
Please post down your program's code, I'd be glad if it could corrupt files on my harddrive :twisted:
> You cannot give more Reputation to anuizath2007 today.
<arnie>
I'll be back!
</arnie>
Haha, bookmarked in my reputation queue :P
Is using code tags really that difficult for you?
Haven't you found the button yet, after 49 posts?
Information about code tags is found all over the website:
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) any place CODE tags were used
6) Even on the background of the box you actually typed your message in!
How can you just neglect that? There's no explanation solid enough to not use code tags.
Please come back when you've learned how to use code tags, and when you've learned to use int main()
instead of void main()
. void main()
is evil, but some people just don't seem to get it.
Come on, you started your thread in the wrong forum and it seems like you're still not aware of the fact that you won't get helped.
It's maybe better to not waste your time on wasting my time, I would really appreciate that.
Yep, I saw you were viewing the page, so I posted, THEN edited my post.
How could you see that then? niek_e uses invisible mode.
Also: You should check if
argv[0]
has a value, before passing it to ifstream to open it.
Didn't you mean argv[1]
?
BTW, I like your avatar.
Yes, he's got a nice avatar, don't steal it :P
ROFL: I've only got a Kung Fu Panda :P