473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Arrays Question

6
alright, well ive been having a problem trying to get this code to work,
i have my three arrays

char first[80];
char second[80];
char third[160];

First i have to use the fgets() function to get a string from the user and store the data in the array first.. then do the same for the second array.

next, i have to use the strcmp() function to determine which string is last alphabetically.

then the strlen() function to determine which string is longest.

and last use the strcpy() and strcat() functions to take first join it to second and store the result in the array named third.

I have attempted this, it sounds easy to me, but i cant figure it out, i just need help on this so hopfully it will help me to understand how arrays work alittle better so that i can complete my test and pass.... thanks
Dec 4 '07 #1
9 1441
fr0zen
6
the output should look similar to

Enter a city name: Halifax
Enter another city name: Hamilton
last alphabetically: Hamilton
Longest string: Hamilton
Joined together: HalifaxHamilton
Dec 4 '07 #2
Ganon11
3,652 Expert 2GB
Have you used these functions before? Do you know how they work?

All you need to do, you have already described to us. It's very easy to take your description and write a short program.
Dec 4 '07 #3
fr0zen
6
not really, i don,t really understand C that well.... i can understand code if i read it, i can say this does that and that does this... but its hard for me to make new code
Dec 4 '07 #4
Ganon11
3,652 Expert 2GB
If you don't know how to use the functions, try www.cplusplus.com for looking up what they do. The site also provides several short, practical examples in the function's use. Other than knowing what these functions do, your program will basically write itself, according to that description. It's very clear on exactly what you have to do.
Dec 4 '07 #5
fr0zen
6
if someone could help me with the fgets, i can get it to accept anything
Dec 6 '07 #6
oler1s
671 Expert 512MB
if someone could help me with the fgets, i can get it to accept anything
"can't get it to accept anything" is a vague statement that has no place in programming. I'm guessing you're using the fgets function and either getting compile errors or runtime errors.

First, check the documentation. Understand precisely how to use fgets in your code. Using Google, you should be able to find plenty of documentation on how to use fgets. Typing in "man fgets" (hint: man <something> is a useful google term) will get you documentation.

If you think you have written correct code, and still face problems, you need to show us that code, describe to us your observations that make you think your code doesn't work (errors need to copy pasted here, runtime errors mean you can describe what happens when you run the program).

You need to give us this much information for us to help you properly.
Dec 6 '07 #7
fr0zen
6
int main(){
char first[80];
FILE *file;
{
printf("Enter a city name:");
fgets(first, 80, file);
}
{
printf("%s", first[80]);
}
system("pause");
return 0;}


hopeless?
Dec 7 '07 #8
fr0zen
6
i dont understand char *fgets (char *s, int size, FILE *stream);
Dec 7 '07 #9
primeSo
35
int main(){
char first[80];
FILE *file;
{
printf("Enter a city name:");
fgets(first, 80, file);
}
{
printf("%s", first[80]);
}
system("pause");
return 0;}


hopeless?
fgets() used wrongly, in your case, the last argument is wrong. Try to change it to STDIN. Check it out.

what do you want to do with the file pointer i.e file? are you sure what you are doing will achieve what you expected? do some reading dude. ^.^
Dec 11 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: csx | last post by:
Hi everyone! two quick questions relating to arrays. Q1, Is it possible to re-assign array elements? int array = {{2,4}, {4,5}}; array = {2,3}
19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
12
by: Samee Zahur | last post by:
Back in the days of old C, only numeric literals could be used as dimensions for statically allocated arrays - the size had to be resolved to a constant at/before compile time. Now I'm beginning to...
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
1
by: rir3760 | last post by:
Since a few days ago I have been working with the program I post below (a school assignment). The purpose of the program is to work with the va_ macros (stdarg.h) and arrays of arrays, hopefully...
15
by: Paul Morrison | last post by:
Hi all, I need to come up with some differences between arrays in Java and C, I have searched Google and so far all I have found is the following: Arrays in Java are reference types with...
27
by: jacob navia | last post by:
Has anyone here any information about how arrays can be formatted with printf? I mean something besides the usual formatting of each element in a loop. I remember that Trio printf had some...
3
by: James dean | last post by:
I have created algorithms in C# unsafe code and have fixed the arrays in memory for optimum performance. I use multidimensional arrays rather than jagged arrays. The algorithms i use usually read a...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.