my problem is converting C to java, pls help.....
this the code....
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define FIRST_NAME_LEN 31
#define SECOND_NAME_LEN 51
#define NUMBER_LEN 16
#define MAX_NUMBERS 50
#define TRUE 1
#define FALSE 0
struct Name
{
char firstname[FIRST_NAME_LEN];
char secondname[SECOND_NAME_LEN];
};
struct PhoneRecord
{
struct Name name;
char number[NUMBER_LEN];
};
struct Name read_name();
void show(struct PhoneRecord record);
int has_name(struct PhoneRecord record, struct Name name);
void main()
{
char answer = 'n';
struct PhoneRecord records[MAX_NUMBERS];
struct Name aName;
int count = 0;
int found = FALSE;
int i = 0;
do
{
records[count].name = read_name();
printf("Enter the number for this name: ");
scanf(" %[ 0123456789]",records[count++].number);
printf("Do you want to enter another(y or n)?: ");
scanf(" %c", &answer);
}while(count<=MAX_NUMBERS && tolower(answer) == 'y');
do
{
printf("Enter a name for which you want the number.");
aName =read_name();
for(i = 0 ; i<count ; i++)
{
if(has_name(records[i], aName))
{
if(!found)
{
found = TRUE;
printf("The numbers for this name are:\n");
}
printf("%s\n", records[i].number); /
}
}
if(found)
found = FALSE;
else
printf("No numbers found for this name.\n");
printf("Do you want to search for another (y or n)? ");
scanf(" %c" , &answer);
}while(tolower(answer) == 'y');
for(i = 0 ; i<count ; i++)
show(records[i]);
printf("\n");
}
/* Function to read a name and store it in a Name structure */
struct Name read_name()
{
struct Name name;
printf("Enter a first name: ");
scanf(" %s", &name.firstname);
printf("Enter a second name: ");
scanf(" %s", &name.secondname);
return name;
}
/* Function to output a record */
void show(struct PhoneRecord record)
{
printf("\n%s %s %s", record.name.firstname,record.name.secondname, record.number);
}
/* Function to test whether the name is the same as in a record */
int has_name(struct PhoneRecord record, struct Name name)
{
return (strcmp(name.firstname, record.name.firstname)==0 && strcmp(name.secondname, record.name.secondname)==0);
}
4 5701
my problem is converting C to java, pls help.....
this the code....
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define FIRST_NAME_LEN 31
#define SECOND_NAME_LEN 51
#define NUMBER_LEN 16
#define MAX_NUMBERS 50
#define TRUE 1
#define FALSE 0
struct Name
{
char firstname[FIRST_NAME_LEN];
char secondname[SECOND_NAME_LEN];
};
struct PhoneRecord
{
struct Name name;
char number[NUMBER_LEN];
};
struct Name read_name();
void show(struct PhoneRecord record);
int has_name(struct PhoneRecord record, struct Name name);
void main()
{
char answer = 'n';
struct PhoneRecord records[MAX_NUMBERS];
struct Name aName;
int count = 0;
int found = FALSE;
int i = 0;
do
{
records[count].name = read_name();
printf("Enter the number for this name: ");
scanf(" %[ 0123456789]",records[count++].number);
printf("Do you want to enter another(y or n)?: ");
scanf(" %c", &answer);
}while(count<=MAX_NUMBERS && tolower(answer) == 'y');
do
{
printf("Enter a name for which you want the number.");
aName =read_name();
for(i = 0 ; i<count ; i++)
{
if(has_name(records[i], aName))
{
if(!found)
{
found = TRUE;
printf("The numbers for this name are:\n");
}
printf("%s\n", records[i].number); /
}
}
if(found)
found = FALSE;
else
printf("No numbers found for this name.\n");
printf("Do you want to search for another (y or n)? ");
scanf(" %c" , &answer);
}while(tolower(answer) == 'y');
for(i = 0 ; i<count ; i++)
show(records[i]);
printf("\n");
}
/* Function to read a name and store it in a Name structure */
struct Name read_name()
{
struct Name name;
printf("Enter a first name: ");
scanf(" %s", &name.firstname);
printf("Enter a second name: ");
scanf(" %s", &name.secondname);
return name;
}
/* Function to output a record */
void show(struct PhoneRecord record)
{
printf("\n%s %s %s", record.name.firstname,record.name.secondname, record.number);
}
/* Function to test whether the name is the same as in a record */
int has_name(struct PhoneRecord record, struct Name name)
{
return (strcmp(name.firstname, record.name.firstname)==0 && strcmp(name.secondname, record.name.secondname)==0);
}
Change your struct to class and your printf to System.out.println statements. Do you know any Java at all?
Change your struct to class and your printf to System.out.println statements. Do you know any Java at all?
sorry, but i know a little bit. i just starting to learn for myself. anyway, how about the code i gave, i know tthat you have the class person, name and phonerecord. i confused about writing the main app. could you help?
sorry, but i know a little bit. i just starting to learn for myself. anyway, how about the code i gave, i know tthat you have the class person, name and phonerecord. i confused about writing the main app. could you help?
The code you gave is the C code. You need to write the code for the Person class and post it explaining what you want the main app to be able to do.
Well dude first make urself clear.
You want to rewrite the code in java?(then follow what r035198x said)
or yoyu want to migrate from c++ to java?(then it will need lots of reading in your side.You may start with Herbert Schildt)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Jens Mueller |
last post by:
Hi there,
this is a Java-XML Question, so I am not sure whether this is the
right place, haven't found anything better ....
I try to convert a Java object to XML via SAX and let the FOP...
|
by: Ole |
last post by:
hello,
Little problem:
struct operatable {
char * operatable_id;
int ( * delegate ) ( ... );
somedatatype data;
};
|
by: Ross |
last post by:
Anyone have some code to help me understand how I can convert a given
hex string, say "0009dbaa00004c00000000fb82ca621c," into a struct of
this form:
struct uniqueid {
ulong32_t word1;...
|
by: Mel WEaver |
last post by:
Hello,
I have the following delphi structure for a binary file. I'm looking
for idea how to read this file.
Mel
type
TMenuDataStruct = packed record
exename : string;
|
by: Simple Simon |
last post by:
Java longs are 8 bytes. I have a Java long that is coming in from
the network, and that represents milliseconds since Epoch (Jan 1 1970
00:00:00). I'm having trouble understanding how to get it...
| |
by: dorkrawk |
last post by:
I am having an issue with some VC++ I am writing. I have a struct and
I'm trying to call a function from it from a function in another
object.
here is the struct....
struct JNI_Interface
{...
|
by: shellon |
last post by:
Hi all:
I want to convert the float number to sortable integer, like the
function float2rawInt() in java, but I don't know the internal
expression of float, appreciate your help!
|
by: Marco Nef |
last post by:
Hi there
I'm looking for a template class that converts the template argument to a
string, so something like the following should work:
Convert<float>::Get() == "float";
Convert<3>::Get() ==...
|
by: Debadatta Mishra |
last post by:
Introduction
In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |