473,382 Members | 1,639 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,382 software developers and data experts.

Newb help: Traversing a char *data

joppe
2
Hi!

This is probably a stupid question, but I've searched and tried to find the answear for 4 hours now and im getting a little tired.

Okay here it goes.
I got a list containing a char *data and want to replace every 'a, e' from the data string. Traversing the list and printing out every "line" of data isnt any problem, the problem is when I try to get data[i], or copying the string "head->data" to a sbuffer[maxchars].
Is there any easy way of doing this without changing my "char *data" into a "char data[maxchars]"?


Expand|Select|Wrap|Line Numbers
  1. void rplce(lnode *head){
  2.     char *ans;
  3.     char cbuffer[50];
  4.     int maks = 50;
  5.  
  6.  
  7.     while(head){
  8.  
  9.                                 /*none of em works*/
  10.         /*strcat(cbuffer, head->data)*/
  11.         /*char datacpy[50] = head->data;*/
  12.  
  13.         /*while(ans = strpbrk(head->data, 'aeiouy'){
  14.  
  15.         }*/
  16.  
  17.  
  18.         head = head->next;
  19.     }
  20. }
  21.  
  22. was thinking about doing something like this.
  23.  
  24. while(head){
  25.  
  26.        while(char *ans = strbrk(head->data, 'ae'){
  27.  
  28.        ans = 'i';
  29.  
  30.        /*switching every occurrence of ae in the strings to i*/
  31.  
  32.        }
  33.  
  34.  
  35. head = head->next;
  36. }

Thanks in advance
Joppe
Oct 11 '07 #1
3 2370
weaknessforcats
9,208 Expert Mod 8TB
/*strcat(cbuffer, head->data)*/
/*char datacpy[50] = head->data;*/

/*while(ans = strpbrk(head->data, 'aeiouy'){

}*/
/*strcat(cbuffer, head->data)*/ won't work unless there is a null terminator in cbuffer (which you never initialized)


/*char datacpy[50] = head->data;*/ won't work because the initial value must be a literal string. This shouldn't even compile.


/*while(ans = strpbrk(head->data, 'aeiouy'){ won't work because 'aeiouy' is not a string (it's not a character either). You need a string "aeiouy".
Then strpbrk will return a pointer to the first occurrence of any of these characters.
Oct 11 '07 #2
joppe
2
Thanks for the reply.

Okay let us say that I use while(char *ans = strbrk(head->data, "ae").
It wont compile.
The reason beeing head->data I think.

Compile error:
test.c:108: error: syntax error before "char"
test.c: At top level:
test.c:120: error: syntax error before '}' token

All i want to is to extract the data string from head->data modify it and update it.. If I had used a "char data[X]" instead of "char *data" in my node it would work. But I want to try this with the "char *data".
If I just manage to convert this data into a char[x] I dont even need to use a strbrk, il just use a switch.

But again, everything I try fails.
Any more suggestions?

TIA
Joppe
Oct 11 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
while(char *ans = strbrk(head->data, "ae").
It compiles for me using Visual Studio.NET 2005 priovided head->data is a char*

I suspect another error base on:
test.c:108: error: syntax error before "char"
That is, when your compiler encountered char, it knew it was in trouble. Look upwards from the while statement to see if thgere is something else wrong.
Oct 11 '07 #4

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

Similar topics

5
by: Alexandre | last post by:
Hi, Im a newb to dev and python... my first sefl assigned mission was to read a pickled file containing a list with DB like data and convert this to MySQL... So i wrote my first module which...
6
by: Sean Berry | last post by:
Hello all I have build a list that contains data in the form below -- simplified for question -- myList = ,, ...] I have a function which takes value3 from the lists above and returns...
7
by: berkay | last post by:
i have a txt file; berkay#white jack#black smith#jane writes in it. and after i run the program it only prints smith jane and crashes what is wrong?
10
by: ASiF | last post by:
Hi i am completely novice at programming, would appreciate some help. The program needs to be able to take a set of up to a 100 numbers (between 1 to 9) "inputted" at the prompt and then assign...
24
by: Apotheosis | last post by:
The problem professor gave us is: Write a program which reads two integer values. If the first is less than the second, print the message "up". If the second is less than the first, print the...
11
by: The_Kingpin | last post by:
Hi all, I'm new to C programming and looking for some help. I have a homework project to do and could use every tips, advises, code sample and references I can get. Here's what I need to do....
4
by: plmanikandan | last post by:
Hi, I am new to link list programming.I need to traverse from the end of link list.Is there any way to find the end of link list without traversing from start(i.e traversing from first to find the...
8
by: manstey | last post by:
Hi, I often have code like this: data='asdfbasdf' find = (('a','f')('s','g'),('x','y')) for i in find: if i in data: data = data.replace(i,i)
30
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.