[ create a new paste ] login | about

Link: http://codepad.org/k0Ds4Sej    [ raw code | output | fork ]

C, pasted on Jul 19:
//treating character arrays as strings
#include <stdio.h>

int main () {
	char string [20]; // reserves 20 characters
	char string2[] = "string literal"; //reserves 15 characters
	int i; // counter
	
	printf("Enter a string: ");
	scanf("%s", string1 ); // input ended by whitespace character
	
	printf("string1 is: %s\nstring2 is: %s\n"
			"string1 with spaces between characters is: \n", string1, string2);
		
	for(i = 0; string1[i] != '\0'; i++) {
		printf("%c", string1[i] );
		}
	
	printf("\n");
	
	return 0;
	
	}


Output:
1
2
3
4
In function 'main':
Line 10: error: 'string1' undeclared (first use in this function)
Line 10: error: (Each undeclared identifier is reported only once
Line 10: error: for each function it appears in.)


Create a new paste based on this one


Comments: