baby_c 37 Junior Poster

I STRONGLY suggest using the scanner for this, as it is much easier to use, though it is slightly more limited than other things (in my opinion).

These are declared by using:

Scanner scanner=new Scanner(System.in);

You may get input from the user by using:

scanner.nextInt();
scanner.nextLine();

You should goto: http://download.oracle.com/javase/1,5.0/docs/api/java/util/Scanner.html for more information about the Scanner Class

thank you very much.. I got the point

baby_c 37 Junior Poster

You need to do some more research on the classes you are using.
For example what does the API doc for the DataInputStream class say it is used for?
The data that is read is translated into an internal format, not into Strings.

What happened when you used the BufferedInputStream?

How about trying the BufferedReader class or the Scanner class?

Do a Search on this forum for lots of code samples.

thank you for reply..Actually I was going to study how DataInputStream class is work. But of course I translate the input into byte code. isn't it. I skipped that unknowingly.. Is there any way to translate back this byte code to String ??

baby_c 37 Junior Poster

Hey friends.Need a help from you again.

I'm trying to study about streams and I wrote small code for get input from command line and print it in the screen,but It prints weird characters like Japanese :O . Can anyone explain what I did wrong...

import java.io.*;
public class ReadBytes {

  
    public static void main(String[] args) {
        
        try{
          //  FileInputStream file =new FileInputStream(System.in);
            BufferedInputStream buff = new BufferedInputStream(System.in);
            DataInputStream data = new DataInputStream(buff);
            

            
            int count=0;

            try{

            while(true){
                char input =data.readChar();
                System.out.print(input+" ");
                count++;
              }
            }
            catch(EOFException eof){
                buff.close();

            }
            
            System.out.println("\nBytes read:  " +count);
            
        }catch(IOException e){
        System.out.println("Error -- "+e.toString());
        }



    }

}
//output

baby C
扡 批 ⁃
baby_c 37 Junior Poster

Nothing. You can create an ArrayList to hold Item class objects.
One small thing, Java naming conventions for classnames is that they start with a Capital letter.

aha... thanks for the tip :)

baby_c 37 Junior Poster

hi..
In your statement u are initialize array with
item[] itemAr = new item[100];
that is wrong u can not initialize array in that way...u can initialize as..
dataType[] itemAr = new dataType[100];
here dataype may be an int, float,double char .etc...
so if u initialize a array with 100,so that array length is 100.
no mater how many element insert in array...but number of element less then 100.
otherwise ArrayIndexOutOfBoundsException generated..

My data type is "item" , so what's wrong with that..? :-O

baby_c 37 Junior Poster

Have you read the API doc?

Or search on this forum for sample code. There are dozens of examples.

ok I'll find out.thanks

baby_c 37 Junior Poster

No easy way. You have to look at each element and see how it is set.
Arrays are pretty dumb. If you use a collection class like an ArrayList, you can ask it how many items it has in it.

thank you for the reply.Can you please explain something more about ArrayList..? how to create like array one using it..

baby_c 37 Junior Poster

hello friends,

I got a problem with an object array.I'll write a sample code for understand the problem.I declared an array of objects named item.

item[] itemAr = new item[100];

And then I initialized some of them

itemAr[0]=****;
itemAr[1]=****;
itemAr[2]=****;

I want to know that is there a way to find out how many array elements are initialized like this.(In this case its just 3).I tried with item.length but it returns 100 which is the size of array.

thank you all.

baby_c 37 Junior Poster

;)No probs

Please mark thread as solved if it is what you need.

LJ

Sorry.. I was unable to find exactly what I want.The link shows some keylogger tools and sort of thing but not the one I'm searching for..

baby_c 37 Junior Poster

You might want to try one of these. They are free for a trial period, but if all you want to do is check what software on your PC is using your connection, you will probably only need it for a day or two.

They are all available for download at CNet.

http://download.cnet.com/windows/monitoring-software/?filter=os%3D133|&filterName=os%3DWindows+7|&tag=narrow

Good luck

LJ

thanks mate :D

baby_c 37 Junior Poster

hi friends again I need some help.

I'm using a broadband connection and got a problem that I'm ran out of my free data bundle every month and have to pay for the additional data.. but I'm not download much.All I need to know is is there any software for monitoring the softwares that use my internet connection and how much data are they downloading.. Can any one help me..? thanks you in advanced.

baby_c 37 Junior Poster

hi friends again I need some help.:)

I'm using a broadband connection and got a problem that I'm ran out of my free data bundle every month and have to pay for the additional data.. but I'm not download much.All I need to know is is there any software for monitoring the softwares that use my internet connection and how much data are they downloading.. Can any one help me..? thanks you in advanced.

baby_c 37 Junior Poster

O'Caml is a far better language than Ruby.

oh thank you.. Can you please explain the differences

baby_c 37 Junior Poster

Hey friends ..I need a help.. I want to know that to learn oop concept is RUBY language good...? we have to choose between RUBY and OCAML. Please can anyone explain a bit..Thanks in advance

baby_c 37 Junior Poster

Without even knowing what version of windows you have, nope![/QUOT

I'm using Windows seven 64.. Can You help me please..? thanks for the reply

baby_c 37 Junior Poster

hi friends.. I got some problem with my new laptop... I tried to partition my hard's free space and by mistake a have mark a drive as the active.And when I try to restart the laptop it says "boot-mgr is missing".Can anyone explain how to fix this using a usb flash drive please... Thank You all for your time...

baby_c 37 Junior Poster

See:
this
this
this
and
this

thank you specially.. learnt lots of things..

WaltP commented: Thanks +15
baby_c 37 Junior Poster

thanx for all responing ... i was unable to connect internet last days.. thank you you again..

baby_c 37 Junior Poster

Hi friends, well... i'm asking for another help from you guys.hope you will...

My friend sent me a email asking why the following code doesn't work properly.I'm also couldn't understand what's happening..When this program run it supposed to prompt two times to enter values.but its actually prompt once. I tried to clean input buffer,but it seems like the same.please anyone can help.I'm sure you guys can..thank you in advanced. i'm running this on ubuntu.

#include<stdio.h>
#include<string.h>
void main()
{
    
    char check[5];                       
                                                 
    prter:intf("En-        ");    
   scanf("%s",check);            
    printf("%s\n",check);
    printf("%.2s\n",check);
    printf("Re-Enter:-    ");
    fflush(stdin);
   gets(check);
    printf("%s\n",check);
}
baby_c 37 Junior Poster

Sorry, I hope it DOES "make her paranoid". I am just hoping to avoid what happened to good friend's granddaughter, 12 years old when it began, right here in my county. She recorded a "sexy" message to a boy she didn't know, but thought was "cute" at another middle school here, got his email address and sent it to him, hoping he would reply. He didn't, instead he sent it to some of his friends and within a week it had been sent multiple times to different students at all the other middle and high schools (there are 9 middle schools and 7 high schools) in the county. Kids who knew her recognized her voice, she didn't give her name in the recording, but one of them played it for his mother, because he thought it was wrong to send something like that. His mother contacted her mother and all "h" broke lose. They got the name of the original receiver and contacted his parents, he confessed he had sent it to a "couple" others. It went around our area for about a month and stopped, for awhile. Then it began again only this time somebody had added pictures to illustrate what the recorded message said. It is still going around and not only here in our state because the original girl who sent it out has now received it back from people she knows out of state with a message that says, "this girl sounds like you." It should …

baby_c 37 Junior Poster

Crikey, j, you'll make everyone paranoid. Well, not quite everyone, Facebook will go on...
And yes, the file will be in a "temp" store on his computer [as well as any place he saves it to], and will stay there until he cleans or it is cycled out with age... could be months. And even then it will remain on disk, not at all lost, until it is overwritten...
Baby, we must hear this file.... we just must.. :)

:D

baby_c 37 Junior Poster

Not if you have sent it on to somebody else. Once it's on their computer, facebook, cellphone, whatever, then it is "out there" and even deleting it from your computer or phone makes no difference, somebody else has it and they can do whatever they want with it.
Number one rule about the internet...Don't say or send anything to anybody that you don't want the world to see or hear, because after you it send to another, then it is out of your hands for good.

That person can delete the file from his computer and it's gone from his, but you have absolutely no guarantee that person will do that, even if they say they will. Don't send it to somebody else.

Oops..can i upload it some webpage and allow him only to listen...?anyway thanx for reply..

baby_c 37 Junior Poster

hi friends.. i need to know that is there any method to allow someone to access a file just one time,and delete that file itself.I just wanted to send some audio file to my friend and doesn't want to keep evidence of it..Is there anyway.... thanx in advance.

baby_c 37 Junior Poster

Because a returning function will invalidate all its variables, you can't return the address to any of them and expect consistent results...Here's one way to solve your problem using the heap.

#include <stdio.h>
#include <stdlib.h>

#define ARR_SIZE 4

int* foo(void);

int main()
{
	int i = 0;
	int *ans = foo();

	for (; i < ARR_SIZE; ++i)
		fprintf(stdout, "ans->%d\n", ans[i]);

	free(ans);
	return 0;
}

int* foo(void)
{
	int i = 0;
	int *ar = (int*)malloc(ARR_SIZE * sizeof(int));
	
	for (; i < ARR_SIZE; ++i)
		ar[i] = i + 10;

	return ar;
}

oh!thats the way...itz very helpful thanx a lot...

baby_c 37 Junior Poster

You have to create your array on the heap in this situation...Returning an address to an array on the stack won't work because the address is invalid as soon as the function returns..

thanks for your quick reply.but i don't fully understand your explanation..can you explain it in another way..thanks

baby_c 37 Junior Poster

You have to create your array on the heap in this situation...Returning an address to an array on the stack won't work because the address is invalid as soon as the function returns..

thamks for your quick reply.but i don't fully understand your explanation..can you explain it in another way..thanx

baby_c 37 Junior Poster

please anyone help me to catch this.i tried to return an array from function and access it within main function.i just got a warning

"function returns address of local variable
 "

and when i execute the program it gives garbage values as array elements..cam you help me pls...

#include<stdio.h>

int *foo(void);

int main()
{
int i;  
int *ptr=foo();


for(i=0;i<4;i++)
printf("%d	",*(ptr+i));

return 0;
}


int *foo()
{

int ar[4]={1,2,3,4};



return ar;
}
baby_c 37 Junior Poster

Because you passing a copy of i to your function it will never increment the global i.

yeah...thats true..but how could that happen...

baby_c 37 Junior Poster

Create your function like this

void increment( int *i )
{
   ++(*i);
}

and call it by passing the address of i

increment( &i );

no.i just need to explain whats going on..please help me for that..thanks for your reply..

baby_c 37 Junior Poster

I have declared a global variable. But when i assign the "i" in the loop as the function parameter, the global variable does not chang. It seems that it creats another variable "i" and assigns it to that "i". Is it possible once i have declared the global "i"?? I'm little bit confused.Can u plz explain it n hlp me out.:):?:

#include <stdio.h>
int i;
void increment( int i )
{
   i++;
}
int main()
{
   for( i = 0; i < 10; increment( i ) )
   {
   }
   printf("i=%d ", i);
   return 0;
}

thnx in adv...:-O

baby_c 37 Junior Poster

hello friends..i need some help here..

my os is windows seven,and i installed linux for a educational matter.then when i boot the computer i had to choose the os from the grub.And today morning i formatted the partition which is linux installed.then i unable to boot from windows seven.After that i installed windows seven to the partition which is formatted.now i'm using that one.But i still unable to boot into my old windows seven .here's the problem.. .how can i recover the old seven and boot into it..please somebody help me..


the C: {marked as (2)} is the new windows seven
D:{marked as (1) is my old windows seven}

baby_c 37 Junior Poster

Where did you get the 4559877 number? That's way big!

Correct is sqrt() of bigNum or 775,146 (and the decimal places thereafter you can forget about).

** I'm talking about line #34 in your program, not the fmod() line of code. **

Windows calculator will handle and confirm the above number.

Did you try the suffix ULL in gcc or C-free, for unsigned long long int's, yet?

Sree ec says they work in gcc for both 32 and 64 bit versions.

sorry that's a mistake .. the number is 600851475143

baby_c 37 Junior Poster

Post up your code, and I'll see what's up with it. I've run it through with the big number about 50 times now, with no problem.

You have the big number assigned to a long double? And your printing it with %Lf, instead of just %lf?

#include<stdio.h>
#include<math.h>


int main()
{
int c2;
long lprime=2,prime,n=3;

do
{
	for(c2=2;c2<n;c2++)
		
		if(n%c2==0)
		break;
	
	else
	{	
		prime=n; 	
		if(c2==n-1)
		{
		if(fmod(4559877,prime)==0)
			{
				lprime=prime;	
				//printf("%ld \n",prime);	
			}
		
			
		//printf("%ld \n",prime);	
		break;
		}
	}	
n++;
}while(n<4559877);
		printf("%ld\n",lprime);
return 0;
}
baby_c 37 Junior Poster

It would have been rather difficult.

However, since then, I have found a fun little scamp called fmod(). fmod() is in math.h (so include it if you haven't already), and what it does is give you the modulo (remainder) for the two doubles that you give it:

result=fmod(double, double);

So with that help, it became very easy to cast my unsigned long int I had found was a prime number, already, into a long double like bigNum, and have it tell me when the two were zero - that is, when the prime number I'd just found, was a factor of bigNum.

Oh yeah! ;)

so first, get the prime number
then result=fmod(bigNum, primeNumber)
if(result equals zero)

  • then primeNumber is a factor
  • save it as the biggest factor so far, if you're
  • genererating prime's from small to large.

end of if

print up your summary and the biggest prime factor.

Check out fmod() and see if it's included in your compiler's functions.

that worked for some range..but for my BIG number it run and stuck at command prompt..

baby_c 37 Junior Poster

You don't have to act << SO >> surprised!! ;) ;)

This is just the first part, of course. Lots more to be done.

U think that i can't do the rest by my self..?

baby_c 37 Junior Poster

I've thought this through a bit more. You can do this with your current compiler. It's not as easy, but here's how:

Make the bigNum a long double data type. Add #include <math.h> for the floating point packages (doubles and floats both).

Now take the sqrt() of bigNum (800 651 475 143.00), and put that sqrt() into another long double variable. Let's call that variable numbr.

Then an unsigned long int num = numbr / 1; //yes, that's a one

Which will get rid of all the digits after the decimal place, and we'll have the right number we want - 775,146.

That's the highest possible prime number less than bigNum. Now you can deal with a much smaller number, and avoid bigNum, for now. An unsigned long int will handle 775,146 very easily.

All you have to do now, is find the largest prime number below 775,146, that is also evenly divisible into bigNum.

Once we have all the prime numbers, we can use an int array to test those numbers, and just repeatedly subtract to simulate division. (Much easier than doing long division with int arrays).

It won't be blazing fast, or all that easy, but if you can't find other solutions you like, it's a way to do it.

This is a bit muddled, but shows getting to the sqrt() of the bigNum, and putting it into an unsigned long int. This was done on an old 16 bit compiler (Turbo C):

/* a program to find …
baby_c 37 Junior Poster

Hmmmm...

Any hints from the book or teacher?

What is your operating system?

I know the 64 bit compilers (and maybe some 32 bit compilers), will allow long long int's, but I'm not sure which one's, exactly.

Might be a way of doing this using a string of individual int's in an int array, but I'm not familiar with it.

OK, well a few things to look for then:

1) A 64 bit compiler that will run on your OS, and (hopefully free) and has long long int's.

and

2) A way to work with int's in an int array, to use the array, as our big number

3) GNU has a BIG INT library that I'm sure could handle this. Is it OK for you to use a library like that, in your program?

1)My next move is this,use a 64 bit compiler..
2)i don't think i can do that.because i don't very good at that array stuff.
3)yeah..no problem,i need to solve this anyway.don't worry about the method...

i'll inform you when i finished go through these ways..thanks dear.:)

baby_c 37 Junior Poster

Did you try using "long long int" and "unsigned long long int"?

both give the same warning..:(

baby_c 37 Junior Poster

yeah..i have to find a way to store the number this way or have to find a another way to solve this problem...I'll try in gcc again..

when using gcc the program complie with a warning
3(prime factor).c: In function ‘main’:
3(prime factor).c:8: warning: integer constant is too large for ‘long’ type

and when it executed,nothing displayed,just stuck at terminal

baby_c 37 Junior Poster

I'm not familiar with C-free, but it appears to be in a cpp (C++) directory. Gcc should have a long long int, and hopefully, an unsigned long long int.

It's going to be quite difficult to find a prime number, if we can't find a data type that we can use to hold the number for us. I don't know of any way to find a prime number, of a string. (Might be a way, but I haven't thought of one yet).

Did your teacher or book talk about some way to use a string as a number to find it's prime factor?

There are BIG INT libraries of course, but I doubt if that's what was intended for you to use.

yeah..i have to find a way to store the number this way or have to find a another way to solve this problem...I'll try in gcc again..

baby_c 37 Junior Poster

What compiler are you using?

The previous errors occurred when using C-free on windows..
But i usually use gcc compiler on ubuntu..it also give errors.

baby_c 37 Junior Poster

Does your compiler support type long long int, or unsigned long long int, and will it now handle your 12 digit integer, OK?

no it doesn't... gives

[Error] C:\Users\SUDHEERA\Documents\C\prime.cpp:4: integer constant out of range
[Warning] C:\Users\SUDHEERA\Documents\C\prime.cpp:4: warning: decimal integer constant is so large that it is unsigned

baby_c 37 Junior Poster

Edit: Does your compiler support long long int's? or even unsigned long long int's? Try those out.


Now, let's think about finding this greatest prime factor.

You aren't REALLY going to search for a prime number less than N, and ACTUALLY go all the way up to N are you? :(

Oh dear!

Do a little Googling, and come back and tell me where the highest number you need to search, really is?

Then we'll chat some more.

yeah..!i may be i have to think about this further more...thanks for the help...

baby_c 37 Junior Poster

Looks like your compiler is telling your to use unsigned long int. Try that, one time.

*Always pay attention closely to any compiler error or warnings!*

Learning to debug is an important part of programming, and using compiler messages is a critical part of that.

thanks for trying...but it gives the same error..

baby_c 37 Junior Poster

hey friends..i'm trying to make a program to find the largest prime factor of a number of 12 digits.but i'm unable to figure out that what's the appropriate variable type for that.can u guys help me...

#include<stdio.h>
int main()
{
int c2;
unsigned long nbr=600851475143,lprime=2,prime,n=3;

do
{
	for(c2=2;c2<n;c2++)
		
		if(n%c2==0)
		break;
	
	else
	{	
		prime=n; 	
		if(c2==n-1)
		{
		if(nbr%prime==0)
			{
				lprime=prime;	
				//printf("%ld \n",prime);	
			}
		
			
		//printf("%ld \n",prime);	
		break;
		}
	}	
n++;
}while(n<nbr);
		printf("%ld\n",lprime);
return 0;
}

this code gives following...

3(prime factor).c: In function ‘main’:
3(prime factor).c:5: warning: integer constant is too large for ‘long’ type
3(prime factor).c:5: warning: large integer implicitly truncated to unsigned type

baby_c 37 Junior Poster

hello friends...i need some help again.it's little hard to understand that whats the use of
ungetc() function.Can you people explain that with some examples.please..i'm still learning.And new to this stuff..

baby_c 37 Junior Poster

oh! i got it..thank you friend.this is what i tried.(not the complete one).

#include<stdio.h>

struct matrix* read(void);

struct matrix{
	int mat_1[3][3],mat_2[3][3];
};

int main()
{
	int i,j;

	
	struct matrix* p = read();

	
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			
			printf("%d	",p->mat_1[i][j]);
		//	p++;
		}
		puts("");
	}
	
	
}


struct matrix* read()
{
	int i,j;
	struct matrix matA;
	
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			matA.mat_1[i][j]=i+j;
			matA.mat_2[i][j]=i-j;
				
		}
	
	}
	
return &matA;
}
baby_c 37 Junior Poster

thanx for your reply...but i'm little confuse at line 17.what's the use of foo();.Can you please explain that?..

baby_c 37 Junior Poster

hey friends i need help once again...

i need to know that how to accessing a structure in another function using pointers.i mean when we returning a pointer to the main function we have have the address of the structure.how to use that address to access the structure..pls guys help me.i'm still learning.:S

baby_c 37 Junior Poster

hey guys..i need some help here.

i want to network both desktop which running ubuntu 10.04 and laptop with windows seven.and i have the cable but i don't know about anything networking.can you please explain step by step please...