Sponsored Content
Top Forums Programming Some error with number of keyboard inputs occured with this code for reversing a string.. Post 302535055 by mscoder on Wednesday 29th of June 2011 01:27:36 PM
Old 06-29-2011
Some error with number of keyboard inputs occured with this code for reversing a string..

i used a two-way linked list "node" for the code::
Code:
#include<stdio.h>
#include<malloc.h>

void insert();
void reverse();

struct node
{
	char c;
	struct node *next;
	struct node *back;
}*start=NULL;


int main()
{	
	int n,i;
	
	printf("Enter the size of the string to be reversed\n");
	scanf("%d",&n);
	printf("Now enter the %d character of the string one at a time",n);

	for(i=0;i<n;i++)
	{
		insert();
	}	
	
	reverse();	

	return(0);
}

void insert()

{	
        printf("\nEnter the character:\n");
	char w;
	scanf("%c",&w);

	struct node *tmp;

	tmp=malloc(sizeof(struct node));
        tmp->c=w;
        tmp->next=NULL;
        


        if(start==NULL)
                {
                       tmp->back=NULL;
                       start=tmp;
                }

        else
                {   
                        struct node *q;
                        q=start;
                     
                        while(q->next!=NULL)
                        {
                                q=q->next;
                        }
                     
                        tmp->back=q;
                        q->next=tmp;
                }
}	


void reverse()
{
	struct node *p=start;
	while(p->next!=NULL)
        {
                p=p->next;
        }


        printf("\nThe reversed string is :\n");


        while(p->back!=NULL)
        {
                printf("\t%c",p->c);
                p=p->back;
         }
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reversing and trim a String through SHELL script

All I want to reverse and trim a string using UNIX shell scripts.Iam using Bourne shells. Can you help me? Thanx in advance Regards Deepak (5 Replies)
Discussion started by: DeepakXavier
5 Replies

2. Shell Programming and Scripting

output string in reversing order

If I have string { I_love_shell_scripts} anyone knows how to have output {stpircs_llehs_evol_I} by using shell and perl ?I know in perl, there is reverse() funcation, but can it be done by not using reverse()? (3 Replies)
Discussion started by: ccp
3 Replies

3. Shell Programming and Scripting

read n number of inputs

Hello, I think its a sinple query but somehow i m stucked up here... I am trying to enter n number of inputs from the user and write them in an input file ie row wise... I tried standard commands like $echo "enter the inputs for the file" $read var1 var2 var3 var4 test1 test2... (14 Replies)
Discussion started by: er_aparna
14 Replies

4. UNIX for Dummies Questions & Answers

Help how replace stardard keyboard inputs by arguments at run time of a script

Hello Everybody, Please help. I was trying to automate the use of a third-party given shell script. The script is written to be used at run-time to collect a few variables to be provided by the user through key board, in the fashion as below: ./runcommand please provide a file name to... (6 Replies)
Discussion started by: Dingrong
6 Replies

5. Shell Programming and Scripting

reading and reversing a string

Hi Everyone....I am new to Unix and BASH programming...I just want to read a string and reverse it and display.....can anyone help me out???? (8 Replies)
Discussion started by: nikhilneela
8 Replies

6. Shell Programming and Scripting

Need help reversing this code

ssh servername.com "echo /$APP=$BUSIN >> $URI; echo /$APP/*=$BUSIN >> $URI" Ok for example here i ssh into a example servername.com, and I think what it does some line gets put into the urifile , my question is, how would i go about removing that in a script. in summary, the above code is... (3 Replies)
Discussion started by: new2learn09
3 Replies

7. UNIX for Advanced & Expert Users

Error occured while running a script

Hi All, In my application, I'm getting an error as type mismatch Let me now explain the scenario, I ran a shell script which calls some other scripts. All these scripts uses the environment variables. Take for example, this script uses a variable 'PathDir'. I initiallized the value to... (2 Replies)
Discussion started by: iamgeethuj
2 Replies

8. UNIX for Dummies Questions & Answers

Newbie Alert:Reversing part of a string?

Hello all, Wondering if anyone can help me out. Trying to cut the names out of the /etc/passwd file so that they can be displayed first then last name. I cut them out and put them into variables but cant get them to display side by side after cutting. Anyone able to help a newbie? (1 Reply)
Discussion started by: losingit
1 Replies

9. Shell Programming and Scripting

Automation of keyboard inputs..like Ctrl+d and Ctrl+a

Hi..! I'm stuck with my automation of starting a process and keeping it running even after the current ssh session has exited.. So i'm trying to use command 'screen'. which is doing exactly what i wanted, But the problem is automation of the same. i will have to press Ctrl+a and Ctrl+d for... (2 Replies)
Discussion started by: chandana hs
2 Replies

10. UNIX for Dummies Questions & Answers

How to send keyboard inputs toa UNIX command executed from a shell script?

I have a unix command that prompts for 'y'. How do I run this from my shell script? (4 Replies)
Discussion started by: Sree10
4 Replies
DOMNODE(3)								 1								DOMNODE(3)

The DOMNode class

CLASS SYNOPSIS
DOMNode DOMNode Properties o publicreadonly string$nodeName o public string$nodeValue o publicreadonly int$nodeType o publicreadonly DOMNode$parentNode o publicreadonly DOMNodeList$childNodes o publicreadonly DOMNode$firstChild o publicreadonly DOMNode$lastChild o publicreadonly DOMNode$previousSibling o publicreadonly DOMNode$nextSibling o publicreadonly DOMNamedNodeMap$attributes o publicreadonly DOMDocument$ownerDocument o publicreadonly string$namespaceURI o public string$prefix o publicreadonly string$localName o publicreadonly string$baseURI o publicreadonly string$textContent Methods o public DOMNode DOMNode::appendChild (DOMNode $newnode) o public string DOMNode::C14N ([bool $exclusive], [bool $with_comments], [array $xpath], [array $ns_prefixes]) o public int DOMNode::C14NFile (string $uri, [bool $exclusive], [bool $with_comments], [array $xpath], [array $ns_prefixes]) o public DOMNode DOMNode::cloneNode ([bool $deep]) o public int DOMNode::getLineNo (void ) o public string DOMNode::getNodePath (void ) o public bool DOMNode::hasAttributes (void ) o public bool DOMNode::hasChildNodes (void ) o public DOMNode DOMNode::insertBefore (DOMNode $newnode, [DOMNode $refnode]) o public bool DOMNode::isDefaultNamespace (string $namespaceURI) o public bool DOMNode::isSameNode (DOMNode $node) o public bool DOMNode::isSupported (string $feature, string $version) o public string DOMNode::lookupNamespaceURI (string $prefix) o public string DOMNode::lookupPrefix (string $namespaceURI) o public void DOMNode::normalize (void ) o public DOMNode DOMNode::removeChild (DOMNode $oldnode) o public DOMNode DOMNode::replaceChild (DOMNode $newnode, DOMNode $oldnode) PROPERTIES
o $nodeName -Returns the most accurate name for the current node type o $nodeValue -The value of this node, depending on its type o $nodeType -Gets the type of the node. One of the predefined XML_xxx_NODE constants o $parentNode -The parent of this node. If there is no such node, this returns NULL. o $childNodes - A DOMNodeList that contains all children of this node. If there are no children, this is an empty DOMNodeList. o $firstChild - The first child of this node. If there is no such node, this returns NULL. o $lastChild -The last child of this node. If there is no such node, this returns NULL. o $previousSibling - The node immediately preceding this node. If there is no such node, this returns NULL. o $nextSibling - The node immediately following this node. If there is no such node, this returns NULL. o $attributes - A DOMNamedNodeMap containing the attributes of this node (if it is a DOMElement) or NULL otherwise. o $ownerDocument -The DOMDocument object associated with this node. o $namespaceURI -The namespace URI of this node, or NULL if it is unspecified. o $prefix -The namespace prefix of this node, or NULL if it is unspecified. o $localName -Returns the local part of the qualified name of this node. o $baseURI - The absolute base URI of this node or NULL if the implementation wasn't able to obtain an absolute URI. o $textContent -This attribute returns the text content of this node and its descendants. NOTES
Note The DOM extension uses UTF-8 encoding. Use utf8_encode(3) and utf8_decode(3) to work with texts in ISO-8859-1 encoding or Iconv for other encodings. SEE ALSO
oW3C specification of Node PHP Documentation Group DOMNODE(3)
All times are GMT -4. The time now is 02:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy