What is the error in this simple code:

#include <stdio.h>

int main()
{
	char a[100];
	int c;
	int i = 0;
	int x = 0;

	while( ( c = getchar() ) != '\n' ) {
		a[x++] =c;
	}

	a[x] = '\0';

	while( ( a[i] != '\0' ) || ( a[i] != '.' ) ) {
		printf( "\ni = %d", i );
		i++;
	}

	return 0;
}

The second while loop does not stops and hence gives a segmentation fault

Compiler gcc 4.6.1
OS: Ubuntu 11.10

replace || with &&.

replace || with &&.

Yeah, got the mistake and came to remove this silly thread, and saw your reply
Anyways lots of thanks for helping..

print all the values of the array so you can see what happened

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.