Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /*Finds X in map and returns position*/
- int findX(char map[1000][1000], int i, int j){
- int x, y;
- for(x = 0; x < i; x++){
- for(y = 0; y < j; y++){
- if(map[x][y] == 'X'){
- return x*j + y;
- }
- }
- }
- return -1;
- }
- /*Reads a char map*/
- void readMap(char map[1000][1000], int i, int j){
- int x, y;
- for(x = 0; x < i; x++){
- for(y = 0; y < j; y++){
- /* Reads char to correct matrix position*/
- scanf("%c", &map[x][y]);
- }
- getchar();
- }
- }
- int main(){
- /* Map width and height */
- int w, h;
- printf("What are map's demensions?\n");
- scanf("%d %d", &w, &h);
- getchar();
- /* The map*/
- char map[1000][1000];
- readMap(map, w, h);
- int r = findX(map, w, h);
- if(r == -1){
- printf("Thre's no X\n");
- }
- else{
- int x = r/w;
- int y = r%w;
- printf("X is in position %d, %d\n", x, y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement