Thread: Printing out a matrix of characters

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > scanf("%s",matrix[i]);
    The problem here is you're reading a string, not a char.

    Perhaps
    scanf(" %c",&matrix[i][j]);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    12
    Quote Originally Posted by Salem View Post
    > scanf("%s",matrix[i]);
    The problem here is you're reading a string, not a char.

    Perhaps
    scanf(" %c",&matrix[i][j]);
    Yup, tried that. Doesn't work either.

    Code:
    #include<stdio.h>
    main()
    {
    	char **matrix;
    	int i,j;
    	int row,col;
    	
    	printf ("Rows: ");
    	scanf ("%d",&row);
    	printf ("\nColumns: ");
    	scanf ("%d",&col);
    	
    	matrix=(char**)calloc(row,sizeof(char*));
    	for(i=0;i<col;i++)
    	matrix[i]=(char*)calloc(col,sizeof(char));
    	
    	for(i=0;i<row;i++)
    	
    	{
    		for(j=0;j<col;j++)
    		{
    			scanf("%c",&matrix[i][j]);
    			if(matrix[i][j]==matrix[0][col-1])
    				printf("Top right corner is: %c\n",matrix[i][j]);
    		}
    	}
    Doesn't really work properly as the integer one I made

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing non-printing characters in ^ and M- notation
    By sbeard22 in forum C Programming
    Replies: 6
    Last Post: 10-03-2008, 11:12 PM
  2. Printing only certain characters
    By dmkanz07 in forum C Programming
    Replies: 9
    Last Post: 04-18-2007, 07:40 AM
  3. Printing with Unicode characters
    By chibisetsuna7 in forum C Programming
    Replies: 15
    Last Post: 06-19-2006, 10:26 PM
  4. Printing different representations of characters...
    By smoothdogg00 in forum C Programming
    Replies: 3
    Last Post: 03-04-2006, 01:05 PM
  5. Printing a Matrix?
    By Nebbuchadnezzar in forum C++ Programming
    Replies: 4
    Last Post: 07-08-2005, 08:11 PM

Tags for this Thread