0
L = [[" " for i in range(10)] for j in range(10)]

for i in range (10):
    L[9][i]="*"
for i in range (10):
        L[8][i]="1"
for i in range (10):
        L[7][i]="*"
for i in range (10):
        L[6][i]="3"
for i in range (10):
        L[5][i]="*"

print(L)
print()

def Check_Lines(l):
    for i in range (10):
        x=l[i].count("*")
        if x == 10:
            print ("LINE IS FULL")
            del l[i]
            l.reverse()
            l.append([" "," "," "," "," "," "," "," "," "," "])
            l.reverse()


Check_Lines(L)
print (L)

I wrote the above function in Python as I am more familiar with the python language. What it does is searches a 10 by 10 list and if a single row is filled with * then it would delete it and put a new empty row at the top.

I know c does not have the list functions I used. Is there any easy way of going about what I am doing?

3
  • What have you tried? C language surely doesn't have a native way to manage dynamic lists, what you have are arrays but to use them in a dynamic way you need to work with pointers. Commented Jun 28, 2013 at 17:58
  • I didn't know where to begin to rewrite the built in functions with c. I was more of trying to get someone to respond with what you said "Pointers" so I can look it up and understand what I need to do. I don't know the C language at all and I am trying to learn. Commented Jun 28, 2013 at 18:01
  • Do some research on linked lists. You'll have to implement the list itself, but it'll be an educational experience. :) Commented Jun 28, 2013 at 19:20

1 Answer 1

1

In C unfortunately that problem would be pretty difficult. Would require you to allocate a memory block for your matrix. And when you wanted to "remove" a row you'd have to move everything up and free the extra memory at the bottom of the matrix.

If you can use C++ this is much more easily done with STL containers. You could have a vector of vectors. Removing a row would be a call to erase:

l.erase(pos)  // pos is an iterator at the row you'd like to remove
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.