473,473 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

array search

2 New Member
hello,

i've been working in c for a few months now, but am relatively new to the concept of arrays. the program that i am working on requires me to read in a string of up to 20 unique characters into an array, and then call a function to read the string, identify the unique characters, and print the characters out on a single line with no white spaces.

that being said my question is how to read through the array (without using a string) and determine which characters are unique, and which have already been used.

i hope this makes sense, and i appreciate any help i can get.

thanks a lot!
Oct 22 '06 #1
3 3370
Banfa
9,065 Recognized Expert Moderator Expert
Try this eaxmple

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(int argc, char** argp)
  5. {
  6.     char Text[] = "Hello World";
  7.     size_t ix;
  8.  
  9.     for(ix=0; ix<strlen(Text); ix++)
  10.     {
  11.         char c = Text[ix];
  12.         putchar(c);
  13.     }
  14.  
  15.     putchar('\n');
  16. }
  17.  
Oct 23 '06 #2
wallyzwurld
2 New Member
Try this eaxmple

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(int argc, char** argp)
  5. {
  6.     char Text[] = "Hello World";
  7.     size_t ix;
  8.  
  9.     for(ix=0; ix<strlen(Text); ix++)
  10.     {
  11.         char c = Text[ix];
  12.         putchar(c);
  13.     }
  14.  
  15.     putchar('\n');
  16. }
  17.  
yeah but that is using the string library, is it not? it makes sense to me that way, but i'm supposed to try to write it w/o using the string... any ideas on that? that's what is throwing me.
Oct 23 '06 #3
Banfa
9,065 Recognized Expert Moderator Expert
the only bit of that that uses the string library is strlen, if you really want to that can easily be re-written as

Expand|Select|Wrap|Line Numbers
  1. size_t myStrLen(const char *pString)
  2. {
  3.     size_t len = 0;
  4.  
  5.     while(*pString++)
  6.     {
  7.         len++;
  8.     }
  9.  
  10.     return len;
  11. }
  12.  
You can similarly re-write all the string library functions, they are all fairly basic.
Oct 23 '06 #4

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

Similar topics

5
by: Nico | last post by:
Hello folks, I am currently storing a set of objects inside an array, $itemlist = array(); $itemlist = new item("myitem"); //... and I am looking to develop a search function, which...
7
by: bettina | last post by:
I want to define an array bidimensional as a session array. <? $continents = array (1 => $europe, $america, $oceania, $africa, $asia); $i = 1; do { $search_countries = mysql_query("SELECT...
5
by: Andrew Poulos | last post by:
If I'm searching for an occurance of a value in a multi-dimensional array how can I get it's index returned as an array, if found? For example, if: foo = new Array(); foo = , 5, , 9, 10]; ...
11
by: deko | last post by:
I need to create a basic one-dimensional array of strings, but I don't know how many strings I'm going to have until the code is finished looping. pseudo code: Dim astrMyArray() Do While Not...
11
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I've noticed a few threads (full of sound and fury, signifying nothing) here recently about allocation of large memory blocks. I'm about to start on a personal pet project where I'll be using...
7
by: simkn | last post by:
Hello, I'm writing a function that updates an array. That is, given an array, change each element. The trick is this: I can't change any elements until I've processed the entire array. For...
1
by: cyrvb | last post by:
Hello, I'm a very very newbie in C# I did start 2 days ago, I get Visual Stuido 2005 C# I try to understand how to manage the arrays I did write this
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
7
by: mark4asp | last post by:
How can I use name:value pairs like an array? 1. I want to load data on to the page which will be used to populate a list box (see example below): <html> <head> <script...
7
by: ianenis.tiryaki | last post by:
well i got this assignment which i dont even have a clue what i am supposed to do. it is about reading me data from the file and load them into a parallel array here is the question: Step (1) ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
1
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
agi2029
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,...
1
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.