tux4life 2,072 Postaholic

For the sake of readability

I don't see how this will make your code more readable.
It will only introduce complexity, and I think it won't be useful anyway, because the initialize(x) macro will only work if no statement has been executed in the function it is "called" from. The preprocessor will replace each "call" to a macro, with the macro's "body". That is, after preprocessing, your code will look like this:

int main() {
  (type example = initfunction()); /* notice the parentheses! */
  example.item = 0;
  return 0;
}

See now why it doesn't compile?
If you want your code to compile, then you should change your intitialize(x) macro definition to: #define initialize(x) type x = initfunction() .
But keep in mind that I'm not for such programming practices, it obscures your code and introduces errors.

[EDIT]
When strictly adhering to the C89 standard, this won't even compile:

#define initialize(x) type x = initfunction()

int main() {
  initialize(example);
  example.item = 0;
  initialize(temp);
  return 0;
}

Why? Because the standard forbids it.
[/EDIT]

tux4life 2,072 Postaholic

I think the error is lurking here:

inp = fopen("first_file", "r");
outp = fopen("second_file", "w");

Your intent was probably:

inp = fopen(first_file, "r");
outp = fopen(second_file, "w");

You should also add checks to see if the file was opened successfully.
And if you're serious about C programming, you'll also want to read this page:
http://www.drpaulcarter.com/cs/common-c-errors.php#4.2

Ancient Dragon commented: Good observation :) +28
tux4life 2,072 Postaholic

Could you at least post code which will compile?
Also please post the defintions of TYPE and DynArr.

tux4life 2,072 Postaholic

Are you sure this is C code?
When compiling with a C compiler:

test.c:1:18: cstdlib: No such file or directory
test.c:2:17: cstdio: No such file or directory
test.c:3:18: cstring: No such file or directory
test.c: In function `main':
test.c:10: error: `new' undeclared (first use in this function)
test.c:10: error: (Each undeclared identifier is reported only once
test.c:10: error: for each function it appears in.)
test.c:10: error: syntax error before "char"
test.c:11: warning: implicit declaration of function `gets'
test.c:12: warning: implicit declaration of function `strlen'
test.c:13: error: syntax error before "char"
test.c:14: warning: implicit declaration of function `strcpy'
test.c:15: error: `delete' undeclared (first use in this function)
test.c:15: error: syntax error before ']' token
test.c:15: warning: implicit declaration of function `printf'
test.c:12: warning: unused variable `b'
test.c: In function `input':
test.c:22: error: `new' undeclared (first use in this function)
test.c:22: error: syntax error before "char"
test.c:24: warning: implicit declaration of function `strtok'
test.c:24: warning: assignment makes pointer from integer without a cast
test.c:29: error: syntax error before "char"
test.c:32: error: `c' undeclared (first use in this function)
test.c:33: error: syntax error before "char"
test.c:26: warning: unused variable `length1'
test.c:29: warning: unused variable `meshok2'
test.c:36: warning: unused variable `gumareli_2'

When compiling with a C++ compiler:

test.c: In function `void input(char*)':
test.c:32: error: `c' was not declared in this scope
test.c:29: warning: unused variable …

tux4life 2,072 Postaholic

now the next task is to create a SINGLE dimensional array with enough size to fit the 2d array and load the 2d array there in row major order.

Well, the first thing you need to figure out is: how many elements should the single dimensional array contain? That's a simple one: just as many as there are in the two dimensional array. How do we get that amount of elements? By using this formula: [I]rows_in_2d_array[/I] [B]*[/B] [I]cols_in_2d_array[/I] .
Following from that formula is the formula which describes how many memory you should allocate using malloc(): [I]rows_in_2d_array[/I] [B]*[/B] [I]cols_in_2d_array[/I] * [B]sizeof[/B]( [I]type_of_2d_array[/I] ) .
Once you've allocated the memory for the one dimensional array, the only thing left to you is copying the elements from the two dimensional array to the one dimensional array. The process is as follows: loop through all the elements of the two dimensional array, then you each time copy the current element from the two dimensional array to the one dimensional array. (Hint: use a variable to keep track of the index where the next element of the two dimensional array should be copied to).

[EDIT]
Don't forget to free the memory you've allocated using malloc().
I can't spot any call to free() in your code, so that means: memory leak.
[/EDIT]

tux4life 2,072 Postaholic

In addition to what Aia said about c = '\t' :
The assignment operator produces a value, values can be used to control an if-statement, like in your example. That's the reason why your code will still compile and run. In C every zero and non-zero value are respectively equivalent for false and true, the '\t' character has a non-zero value thus is equivalent for true.

tux4life 2,072 Postaholic

it is easy

I know. Could you show us your attempt?

tux4life 2,072 Postaholic

Please wrap your code in tags the next time.

Question:

I do not know how to get the program to execute the program's printf() function, bottom portion of the program, to print or show the calculations for the number of blanks, tabs and newlines. There are no compiler or linker errors, but perhaps it is a bug.

Answer:

If you're on Windows, the Ctrl+Z key combination sill signal end-of-file and cause getchar to return the EOF flag rather than extract a character from the stream. On Unix/Linux, the key combination is Ctrl+D.

tux4life 2,072 Postaholic

what does "if (c=='\n')" mean in this context?

It checks if the variable c contains the value of the newline character '\n'.

so if 10 is entered, this is when nl increments up one?

No, if a newline character occurs in the stream you're reading from, then nl increments up one. If you enter 10, then it is not considered as the ASCII value 10, but as two separate characters '1' and '0'.

tux4life 2,072 Postaholic

I am trying to understand why c has to be an integer and not a character for EOF.

http://www.drpaulcarter.com/cs/common-c-errors.php#4.1

Aia commented: Like both links. How to write unmaintainable code is fun. +8
tux4life 2,072 Postaholic

tell me where i am wrong

The flaws are in your encryption routines, here's a fix:

int kk=strlen(cm);
for(i=0,j=0;i<kk;i++) /* changed <= to < */
{
  cm[i]=cm[i]^key[j++];
  if(j==strlen(key))
  {
    j=0;
  }
}

Do the same for your second encryption routine and your program will work the way you intended.

Why does this work?
In your program as it now stands your encryption routine encodes the nul-terminator, which isn't a good thing. If you know what you do, then there's nothing wrong with overwriting a nul-terminator*, but if you do, then you should keep that into account for future operations on that character array, you can't use standard library functions anymore to operate on the string, because such routines make use of the nul-terminator sentinel value to recognize the end of a character array. Since you've overwritten your nul-terminator with a character of your encryption key**, your program will invoke undefined behavior at the time you display your encrypted string using cout. So the logical conclusion is that you should loop one less, that is why you should change: for(i=0,j=0;i<=kk;i++) to: for(i=0,j=0;i<kk;i++) .

* - However I think it's not very useful anyway.
** - [I]nul-byte[/I] [B]XOR[/B] [I]character of encryption key[/I] will reveal that character of the encryption key.

tux4life 2,072 Postaholic

I didn't post this for experienced programmers, I understand it's simple, that's the idea. It's for beginners on the forum, so really it's kind like a tutorial. So you can stop blasting insults at me, and yes I know how to do this, if you will notice the due date on the image said march 3 and since apparently your so intelligent I shouldn't have to tell you that it's may 13th, longafter the due date.

Honestly, you don't know what students would invent to avoid doing their own assignments, I'm long enough on this forum to make that observation. Can you even believe that there are in fact students who spend more time by avoiding work, than by just doing it on their own?
If you really want us to believe you, then you could just post your attempt, even if you've lost it, then you can simply reprogram it quickly. As you said yourself: it's simple. Or are you maybe suggesting the idea that you're superior and that your code is 100% perfect, like many people think? There's a difference between a solution and a good solution, and I'm sure that many folks here are willing to review your attempt, and making suggestions, to make your work even a better solution.

camdaddy09 commented: not an asshole +0
tux4life 2,072 Postaholic
tux4life 2,072 Postaholic

Your code is total rubbish, void main(), conio.h, no code indenting, magic numbers et al. Have you even ever heard about code conventions? I think those boring library and hotel management stuff are already way too difficult for you to code. If you think so high of yourself that you're ready for the real programming, then you should wake up and quit dreaming, because from the code you posted I conclude you're not. This reply may seem harsh, but it's the reality.

jwenting commented: well said +13
tux4life 2,072 Postaholic

the program and logic both are very correct...!!

You didn't carefully read the first post, the OP asked whether there's a solution available which conforms to the ANSI/ISO C++ standard, since your code uses unportable functions (from conio.h), it doesn't conform to the standard, and thereby is not a good solution since it is of no value for the OP. In addition you defined main() as of type void, this is blatantly wrong, the only return type for main() is int, as defined per standard. For the remainder you didn't use code tags to post your code, and your code uses old-style headers.

tux4life 2,072 Postaholic

Change line 36
from: HashSet usedNums = new HashSet(); to: HashSet[B]<Integer>[/B] usedNums = new HashSet[B]<Integer>[/B]();

fabunmi adeniyi commented: this guy is too good +0
tux4life 2,072 Postaholic

A simple rule of thumb is finish up all the expression to the left, then come and evaluate the expression to the right of the pointer

I just follow the operator precedence rules.

Banfa commented: Yes why follow rules of thumb when you can in fact just follow THE rules :D +1
tux4life 2,072 Postaholic

@noobuser:
scanf() leaves the newline character in the input buffer, that's why your code doesn't work the way you intended, this page describes how to fix that.

tux4life 2,072 Postaholic

@0x69:
What I understood was that you state that the following isn't a definition: int *p; .

http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#1.6:

"Object --- a region of data storage in the execution environment, the contents of which can represent values. Except for bit-fields, objects are composed of contiguous sequences of one or more bytes, the number, order, and encoding of which are either explicitly specified or implementation-defined."

From this I conclude that a pointer variable is an 'object'.

http://c-faq.com/sx1/index.html:

"Definition --- A declaration of a variable or function which allocates and optionally initializes (in the case of a variable) or provides the function body (in the case of a function). A definition in this sense is the opposite of declaration, sense 2. See question 1.7. 2. A declaration of a structure, union, or enumeration type which describes the type (and usually assigns a tag) without necessarily defining any variables of that type. 3. A preprocessor #define directive."

Applied to pointer variables: since storage for holding a memory address is allocated and since initialization of the variable is optional, I would conclude that int *p; is a definition.

tux4life 2,072 Postaholic

Well, what does "%n" do in scanf()? I couldn't find any reference to it here.

http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#4.9.6.2:

n No input is consumed. The corresponding argument shall be a pointer to integer into which is to be written the number of characters read from the input stream so far by this call to the fscanf function. Execution of a %n directive does not increment the assignment count returned at the completion of execution of the fscanf function.

Aia commented: Too bad you did not post for him his famous "Google auto-assistant helper" +8
tux4life 2,072 Postaholic

@AD:

That doesn't work

1 2 HelloWorld 3
len = 1
Press any key to continue . . .

int main() {	
  char R[255] = {0};
  int s, e, n;
  scanf(" %n%s%n %d", &s, R, &e, &n);
  int len = e - s;
  cout << "len = " << len << '\n';
  return 0;
}

Pay attention! This is not the C++ forum

True, but you failed to answer the question, most likely because you don't know the answer any more than I do.

It seems to me that it's working correctly, with your input: 1 2 HelloWorld 3 ,
but remember: spaces are delimiters.

First a string is read: "1" (length = 1).
Then an integer is read: 2 .
The remainder stays in the input buffer.

This code fragment illustrates better what I mean:

#include <stdio.h>

int main( void )
{
  char R[81];
  int s, e, n, len;
  scanf( " %n%80s%n %d", &s, R, &e, &n );
  len = e - s;
  printf( "String entered = \"%s\"\tLength = %d\n", R, len );
  printf( "Integer entered = %d\n", n );
  return 0;
}

Sample runs:

1 2 HelloWorld 3
String entered = "1" Length = 1
Integer entered = 2

Hello 89
String entered = "Hello" Length = 5
Integer entered = 89

@AD & @Salem:
Doesn't there have to be a check which prevents an array boundary overrun?
For example:

char str[15];
scanf( "%10s", str …
tux4life 2,072 Postaholic

I also have a C/C++ background, I'm an intermediate programmer, and I'm currently using those books for learning Java:

  • Head First Java 2nd Edition ( Covers Java 5.0 )
  • Big Java 3rd Edition ( Covers Java 5.0 / 6.0 )
    ( Covers Java from a practical point of view, introductory text to Computer Science. A whole bunch of interesting exercises are included! )
  • Java How To Program 8th Edition (Early Objects) ( Covers Java 5.0 / 6.0 )
    ( Covers Java from a practical point of view, introductory text to Computer Science. A whole bunch of interesting exercises are included! )
  • SCJP Sun Certified Programmer for Java 6 ( Covers Java 6.0 )
    ( This book is worth reading if you want to get a very thorough understanding of the Java programming language. Sample exams and review questions similar to those on the Sun certification exam are included! )

Worth mentioning is that all these books assume no Java or previous programming experience, except for the Java certification Study Guide, which requires a basic understanding of Java.

Don't forget reading this as well, it might be of interest:
http://www.daniweb.com/forums/thread99132.html
(a whole bunch of Java resources, probably more than I'd ever use)

tux4life 2,072 Postaholic

The main thing that I concern is whether my English is understandable or not.

Your English is understandable.

tux4life 2,072 Postaholic

1st Piece: Reduce the Calculation

For example: k = (168 * m) / 2; This can be reduced to: k = 84 * m;

Uh? You meant: k = 84 * m / 2;

2nd Piece : Everything Is Not the Same

For example: k *= 2; We can use addition instead of multiplication by: k += k;

AFAIK, k <<= 1; is the most efficient way to do a multiplication by two.

tux4life 2,072 Postaholic

@raymyster:
These are posts written by you:

i post questions here so i can get some scientific feedback from peers who are in the same technology.
unfortunately i made this mistake yet again & i asked here expecting some normal people. it seems this forum is just filled with fcktard heads like you. your only a stupid fool who duno shyt about anything i asked trying to answer stupidly like your knowledge level, just go get a life or f* yourself

check the tag cloud for your profile, it implies a troll that is thinking of suicide:

behaviour cheating clueless evaluation givemetehcode givemetehcodez homework impatient lazy operator precedence spammer spoonfeeding student undefined

if people pick on you in school or your family molests you then don't come and act tough on the internet because in real life your just a loser & you know it.

This is a quote from the forum rules of your own "forum":

b) Members should post in a way that is respectful of other users. Flaming or abusing users in any way will not be tolerated and will lead to a warning. No racism, No religious talk, No sectarian debates.

(Source: Your Programming Community: http://www.coderisland.com)

Every forum has a rule like that one, here's Daniweb's equivalent:

Do not troll by posting anything with malicious intent against another member (including, but not limited to, racist, sexist or religiously prejudiced remarks).

@raymyster:
You as a forum administrator are expecting other people …

tux4life 2,072 Postaholic

@Frederick2:
I don't know much about Windows programming (I once started reading the theForger tutorial, but I stopped somewhere at the very beginning).
However, I could remember something about the Message Loop:

IMPORTANT: GetMessage() will return -1 if it encounters an error. Make sure you remember this, or it will catch you out at some point... even though GetMessage() is defined as returning a BOOL, it can return values other than TRUE or FALSE, since BOOL is defined as UINT (unsigned int). The following are examples of code that may seem to work, but will not process certian conditions correctly: while(GetMessage(&Msg, NULL, 0, 0)) while(GetMessage(&Msg, NULL, 0, 0) != 0) while(GetMessage(&Msg, NULL, 0, 0) == TRUE) The above are all wrong! It may be of note that I used to use the first of these throughout the tutorial, since as I just mentioned, it works fine as long as GetMessage() never fails, which when your code is correct it won't. However I failed to take into consideration that if you're reading this, your code probably won't be correct a lot of the time, and GetMessage() will fail at some point :) I've gone through and corrected this, but forgive me if I've missed a few spots. while(GetMessage(&Msg, NULL, 0, 0) > 0) This, or code that has the same effect should always be used.

I noticed that you also used an "incorrect" version (at least: according to this text).

Ancient Dragon commented: Nice :) +28
tux4life 2,072 Postaholic

In addition, a Win32 API tutorial: http://www.winprog.org/tutorial/.

tux4life 2,072 Postaholic

Won't this method make the moves car1 made on top of car2 and not near?

Oh, now I get what you mean, I first didn't get your example output, now I do. Yes, you're right.

You could use the printf() method for printing the tables, then you don't need to use the tedious '\t' approach. Anyhow, you might want to create a moveCar() method which takes a car as argument, and computes a next move for the car passed to it.
Or, you could first build a string containing the next table entry, by using the format() method from the String class.

tux4life 2,072 Postaholic

I would make a RaceSimulator class with (at least) these abilities:

public interface:

  • an addCar() method, which takes a car as argument, and adds it to an ArrayList of cars for the race.
  • a startRace() method, which simulates a car race, by iterating over the whole ArrayList containing the cars for the race. Then you could use a while loop on a per car basis, like this pseudocode illustrates:
    while ( car has not finished the race ) {
      generate actions for this car
    }
tux4life 2,072 Postaholic

What difference would it make? =S

Found on line 12 of your Simulator.java source file:

while ( car.cmd_start == true ) {
  /*
   * Other code here
   */
}

Your code is correct, but it will not protect you from making typos like:

while ( car.cmd_start = true ) {  // typo, only one '='
  /*
   * Other code here
   */
}

If you use an accessor method instead, such as getStartFlag() , you had to write the loop like this:

while ( car.getStartFlag() ) {
  /*
   * Other code here
   */
}

Now you don't risk your program to turn into an endless loop if you make such a typo.

jeanfrg commented: Great method of avoiding typos. :D +1
tux4life 2,072 Postaholic
boolean cmd_start = false;
boolean cmd_stop = false;
boolean cmd_forward = false;
boolean cmd_reverse = false;
boolean cmd_right = false;
boolean cmd_left = false;

Wouldn't it be a better idea to make these private instead of using the default access specifier?

tux4life 2,072 Postaholic

dunno where shud i start..but am having real trouble understanding file handling...see, i know how to read n write into a file..but lets say i've run the program once n stored some data in to the file say abc.txt, but when i rerun n display the contents it shows the values i entered the first time..the delete function that i use too is useless..on using it n rerunning the program it shows garbage values!!!!

I don't fully understand what you mean, could you maybe post some (minimal) code to demonstrate your problem? Don't forget to use code tags.
Also, please write full English sentences, otherwise your posts are very hard to read.

jonsca commented: Truth is good. I liked your sig link too, btw. +4
tux4life 2,072 Postaholic

How is this connection achieved?

Depends on the implementation.

Input and Output operations can also be performed in C++ using the C Standard Input and Output Library (cstdio, known as stdio.h in the C language). This library uses what are called streams to operate with physical devices such as keyboards, printers, terminals or with any other type of files supported by the system.
Streams are an abstraction to interact with these in an uniform way; All streams have similar properties independently of the individual characteristics of the physical media they are associated with.

(source: http://www.cplusplus.com/reference/clibrary/cstdio/)

tux4life 2,072 Postaholic

Thanks for the reply.. but could someone explain this in a little more detail?

Try this: http://www.cplusplus.com/reference/clibrary/cstdio/

tux4life 2,072 Postaholic

While you're at it, you might find the following linked list tutorial useful:
http://www.eternallyconfuzzled.com/tuts/datastructures/jsw_tut_linklist.aspx

tux4life 2,072 Postaholic

This is just a slightly modified version of the Queue implementation found in the book
C: The Complete Reference by Herb Schildt.
You should take care when using code that was written by Herb Schildt, especially because his code is widely known as buggy code, and you may not have noticed it, but there's a memory leak lurking in the code: in the q_enter() function on line 41, there's this line of code: ptr = (char *) malloc(strlen(str)); .
This line of code dynamically allocates memory, but when does that memory ever get deallocated?
The answer is: never (unless your OS does it, but you should never rely on this).
Another peculiarity can be found on line 40: scanf("%s",str); , well, that's no better than gets(str); since it will still allow an array boundary overrun. You might want to use fgets() instead, or use scanf() in this way: scanf("%99s",str); .
At first sight for the memory allocation problem you might think of a fix like this:

/* this code should execute when main() is entered */
for ( i = 0; i < 100; i++ )
{
  queue[i] = NULL;
}

/* this code should execute before main() returns */
for ( i = 0; i < 100; i++ )
{
  if ( queue[i] )
    free ( queue[i] );
}

However, this is not a very good solution, since it will only make sense when used in this context, it for …

Ancient Dragon commented: nice comments :) +27
tux4life 2,072 Postaholic

In line 29: [B]sizeof(char)[/B] is - by definition - equal to 1.
So this: tempStr = malloc((maxStringLength+2) * [B]sizeof(char)[/B]); .
Could be rewritten as: tempStr = malloc(maxStringLength+2) .
However leaving the sizeof out won't increase performance, since it is evaluated at compile-time, it's just a matter of personal preference.

tux4life 2,072 Postaholic
tux4life 2,072 Postaholic

@Dave: I didn't quite get you when you said:

Here's a better idea for the return value: return an explicit value instead of allowing the possibility of signed integer overflow?

Also, you seem to do exactly the same as I and AD did in your code snippet:
http://www.daniweb.com/code/snippet216567.html .
So, could you please clarify what you meant with returning an explicit value to avoid the possibility of a signed integer overflow ?

[EDIT]
@Dave:
Do you perhaps mean: return (int) *s1 - (int) *s2; ?
[/EDIT]

tux4life 2,072 Postaholic

It's for an assignment so due to the fact that we haven't yet covered arrays I would assume that we can't make use of them in the answers...

That's the most probable, you could however ask your instructor.
Anyways, the code you have so far is probably the simplest you can get, taking your current C++ knowledge into account.

[EDIT]
Since finding the minimum/maximum is a common problem, you might want to do a Google/forum search on this topic.
[/EDIT]

tux4life 2,072 Postaholic

You could perhaps use the ternary operator?

int foo(int a, int b, int c, int d, int e)
{
  int min = a;
  
  min = min > b ? b : min;
  min = min > c ? c : min;
  min = min > d ? d : min;
  min = min > e ? e : min;
  
  return min;
}

But that probably won't do much (since the approach is basically the same as yours), a better approach would make use of an array, in which all numbers are contained, then you could easily loop through all the elements in the array, checking each time if the current element is lower than the lowest element found so far.

tux4life 2,072 Postaholic

I didn't get you "the implementation must convert it..."

The compiler must convert it...

tux4life 2,072 Postaholic

@Jephthah: (In your fixed snippet)
You can replace line 38 ( len = strlen(tempStr); ) by len--; :)

tux4life 2,072 Postaholic

Please be more specific about your problem, also show some effort.

tux4life 2,072 Postaholic

@Ancient Dragon:
Thanks for pointing out this issue, I didn't notice it when I was writing the code. However, the solution you suggest (unfortunately) won't fix the problem, since it will create another one.
If I replace return *(--s1) - *(--s2); by return *s1 - *s2; ,
then strcmp("a", "b") would yield the result 0, and not -1, because both s1 and s2 are incremented by one in the while's expression, s1 and s2 will point to the
nul-terminators by the time the return statement is encountered, and thus return *s1 - *s2; will result in returning 0.

tux4life 2,072 Postaholic

Neither lol.

int i;
for (i = 0;array[i] !='\0';i++)
{ 
    if(array[i] =='\n')
       array[i] = '\0';
}

This won't generate desired output in all cases, let me illustrate this with an example:

Case I: Using WaltP's approach to remove the newline character

#include <stdio.h>
#include <string.h>

int main()
{
  char str[80] = "Hello,\n";
  char *p;
  
  /* let p point to nul-terminator */
  p = str + strlen(str);
  
  printf("Enter your name: ");
  
  /* get a string and add it to the end of str */
  fgets(p, sizeof(str) - strlen(str), stdin);
  
  /* let p point to beginning */
  p = str;
  
  printf("Output:\n\n");
  
  /* WaltP's approach */
  size_t l = strlen(str) - 1;
  if ( str[l] == '\n' ) str[l] = '\0';
  
  printf("%s", str);
  
  return 0;
}

This would generate the following output, when the username WaltP would be entered:

Output:

Hello,
WaltP

Case II: Using Jonsca's approach to remove the newline character

#include <stdio.h>
#include <string.h>

int main()
{
  char str[80] = "Hello,\n";
  char *p;
  
  /* let p point to nul-terminator */
  p = str + strlen(str);
  
  printf("Enter your name: ");
  
  /* get a string and add it to the end of str */
  fgets(p, sizeof(str) - strlen(str), stdin);
  
  /* let p point to beginning */
  p = str;
  
  printf("Output:\n\n");
  
  /* Jonsca's approach */
  int i;
  for (i = 0; str[i] != '\0'; i++) {
    if ( str[i] =='\n' )
      str[i] = '\0';
  }

  printf("%s", str);
  
  return 0;
}

This code would generate the following output, when the username …

tux4life 2,072 Postaholic

>Its keeps animating and i dont know when will this stop...
Answer: Theoretically this won't ever stop, because there's an infinite loop in your main() function:

for ( ; ; ) {
  if ( x > 3 ) x = 0;
  printf ( "%c\b", barRotate[x++] );
  sleep ( 200 );
}

A for-loop defined as such: for ( ; ; ) { } means: 'for ever'. But if you want, you can always add a terminating condition between the two semicolons if you want the loop code to stop executing at some point.

tux4life 2,072 Postaholic

>this is what I started with my knowledge and so far ive got
What you started with your knowledge? Nah, you just copied it from C: The Complete Reference by Herbert Schildt.

jonsca commented: "Aw Schildt!" +2
tux4life 2,072 Postaholic

As it relates to learning Java, you'll also find this material useful:
http://www.daniweb.com/forums/thread99132.html

tux4life 2,072 Postaholic

Please wrap your code in code-tags the next time you post any code.
Whew! That's a lot of errors:

RollingDice.java:12: ';' expected
public static void main (String[] args )
                                        ^
RollingDice.java:16: <identifier> expected
die1 = new Die() ;
    ^
RollingDice.java:17: <identifier> expected
die2 = new Die() ;
    ^
RollingDice.java:19: <identifier> expected
die1.roll() ;
         ^
RollingDice.java:20: <identifier> expected
die2.roll() ;
         ^
RollingDice.java:22: <identifier> expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                  ^
RollingDice.java:22: illegal start of type
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                     ^
RollingDice.java:22: ')' expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                 ^
RollingDice.java:22: ';' expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                   ^
RollingDice.java:22: illegal start of type
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                         ^
RollingDice.java:22: <identifier> expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                          ^
RollingDice.java:22: ';' expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                                        ^
RollingDice.java:22: <identifier> expected
system.out.println ( " Die One: " + die1 + ", Die Two: " + die2 ) ;
                                                               ^
RollingDice.java:24: <identifier> expected
die1.roll() ;
         ^
RollingDice.java:25: <identifier> expected
die2.setFaceValue(4) ;
                 ^
RollingDice.java:25: illegal start …