[QUOTE=DoctorSalt;34596214]Style question for you guys (Keep in mind i'm coding in c#)
How do you capitalize fields, properties, methods and parameters?
The style I've been using it to use camelCase for private fields and parameters.
Public properties and methods are PascalCase.
Also, typically when does one add a "_" before a field (or is it method?) I've seen that before as well.[/QUOTE]
I use ReSharperCase.
[img]http://puu.sh/g5G0[/img]
SFML question here:
I'm making a textbox for my game. Basically what I'm doing is drawing the box, and then the text on top.
However there's a bit of an issue:
[img]http://i.imgur.com/TJPVA.png[/img]
As you can see, since I'm just drawing text, it just keeps going even outside.
Is there a way to perform something similar to sf::Sprite::SetSubRect() but for sf::Text (efficiently?)
I'm pretty sure you have to use OpenGL with SFML to clip in SFML(but I haven't used sfml much, so don't quote me on that)
-----
I'm making a GUI system. I have a base class, well, kind of expected, a "Panel". All other panel types derive from this, such as the button. Now for my problem. I'm implementing a parent/children system. I have that idea planned out but have no clue on how to pass input events. They have functions such as onKeyPress and onMouseDrag but I don't know how to check for the panels under the mouse by traversing the panel tree.
---
In gist:
How do I pass events down to the proper element when all I have is a panel tree?
[QUOTE=marcin1337;34588880]Ok this is really bugging me!
[code]
1 ItemNumber int(11)
2 ItemName varchar(100) latin1_swedish_ci
3 Price double
4 AvailableQuantity int(11)
5 Updated_Dt datetime
[/code]
[code]
private void Form1_Load(object sender, EventArgs e)
{
//Initialize mysql connection
connection = new MySqlConnection(ConnectionString);
//Get all items in datatable
DTItems = GetAllItems();
//Fill grid with items
dataGridView1.DataSource = DTItems;
}
//Get all items from database into datatable
DataTable GetAllItems()
{
try
{
//prepare query to get all records from items table
string query = "select * from items";
//prepare adapter to run query
adapter = new MySqlDataAdapter(query, connection);
DataSet DS = new DataSet();
//get query results in dataset
adapter.Fill(DS);
[/code]
It shows the data that is on the Database fine
[code]
// Set the INSERT command and parameter.
adapter.InsertCommand = new MySqlCommand(
"INSERT INTO items VALUES (@ItemNumber,@ItemName,@Price,@AvailableQuantity,NOW());",
connection);
adapter.InsertCommand.Parameters.Add("@ItemNumber", MySqlDbType.Int16, 4, "1");
adapter.InsertCommand.Parameters.Add("@ItemName", MySqlDbType.VarChar, 100, "ItemName");
adapter.InsertCommand.Parameters.Add("@Price", MySqlDbType.Decimal, 10, "Price");
adapter.InsertCommand.Parameters.Add("@AvailableQuantity", MySqlDbType.Int16, 11, "AvailableQuantity");
adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
[/code]
I followed a website that showed how to use Datagridview and MySQL , but when I try to insert anything using their code I get this.
"Column 'ItemNumber' cannot be null"
[editline]7th February 2012[/editline]
Ok this is really bugging me!
[code]
// Set the INSERT command and parameter.
adapter.InsertCommand = new MySqlCommand(
"INSERT INTO items VALUES (@ItemNumber,@ItemName,@Price,@AvailableQuantity,NOW());",
connection);
adapter.InsertCommand.Parameters.Add("@ItemNumber", MySqlDbType.Int16, 4, "1");
adapter.InsertCommand.Parameters.Add("@ItemName", MySqlDbType.VarChar, 100, "ItemName");
adapter.InsertCommand.Parameters.Add("@Price", MySqlDbType.Decimal, 10, "Price");
adapter.InsertCommand.Parameters.Add("@AvailableQuantity", MySqlDbType.Int16, 11, "AvailableQuantity");
adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
[/code]
I followed a website that showed how to use Datagridview and MySQL , but when I try to insert anything using their code I get this.
"Column 'ItemNumber' cannot be null"
I don't know if this adds anything but I just dragged a datagriview1 onto the form, didn't modify it in anyway.[/QUOTE]
oh wow that website is old. turns out all it takes now is this
[code]
myMySQLCommandBuilder = new MySqlCommandBuilder(adapter);
adapter.UpdateCommand = myMySQLCommandBuilder.GetUpdateCommand();
adapter.DeleteCommand = myMySQLCommandBuilder.GetDeleteCommand();
adapter.InsertCommand = myMySQLCommandBuilder.GetInsertCommand();
[/code]
[QUOTE=ief014;34598273]SFML question here:
I'm making a textbox for my game. Basically what I'm doing is drawing the box, and then the text on top.
However there's a bit of an issue:
[img]http://i.imgur.com/TJPVA.png[/img]
As you can see, since I'm just drawing text, it just keeps going even outside.
Is there a way to perform something similar to sf::Sprite::SetSubRect() but for sf::Text (efficiently?)[/QUOTE]
A hacky way to do it would be to render the text into sf::RenderTexture and then render that onto you sf::RenderWindow.
Literally banging my head on a wall.
Stuck at event handling in c#, its my first time creating my own events in c#
defined my event using
[code]
public delegate void NetReceivedHandler(object sender, EventArgs e, string data);
public event NetReceivedHandler NetRec;
[/code]
and
[code]
public void ListenOnPort()
{
...
NetRec(this, EventArgs.Empty, cData);
}
[/code]
But when I define the new eventhandler, it just won't execute the events.
[code]
public void init()
{
cNet net = new cNet()
Thread async = new Thread(delegate() { net.StartListen( "127.0.0.1", port ); } );
async.Start();
net.NetRec += new cNet.NetReceivedHandler( net_NetRec );
}
private void net_NetRec( object sender, EventArgs e, string data )
{
Console.WriteLine( "Data: " + data );
}
[/code]
I have no idea what I'm doing.
[QUOTE=Map in a box;34598651]I'm pretty sure you have to use OpenGL with SFML to clip in SFML(but I haven't used sfml much, so don't quote me on that)
-----
I'm making a GUI system. I have a base class, well, kind of expected, a "Panel". All other panel types derive from this, such as the button. Now for my problem. I'm implementing a parent/children system. I have that idea planned out but have no clue on how to pass input events. They have functions such as onKeyPress and onMouseDrag but I don't know how to check for the panels under the mouse by traversing the panel tree.
---
In gist:
How do I pass events down to the proper element when all I have is a panel tree?[/QUOTE]
I'm assuming a panel tree is a tree of everything in the UI, in no particular order of importance, besides what is a parent of what.
I traditionally have a panel list (doubly linked lists work great for this), where the front-most panel is always at the start of the list. This makes rendering extremely easy (just render everything on the list, in order, starting at the back) Each panel can be its own tree, but the main panels (the movable and resizeable windows) are not part of any tree.
Once you have a list, sending events is also trivial. Construct a single event object for whatever's happening (I like to separate keyboard and mouse events, though,) and just send it to every panel on the list, in order. When an event 'hits' a panel (it happens within a panel) just set a variable in it to true and continue onward. It's crucial that the event goes to every panel, so that buttons and scrollbars can be released even if the panel is blocked by something. However, when a panel sees that an event has already hit a panel, it will not let any buttons be pressed, etc.
Oh, and what's nice about this system is that when a panel is given focus, just remove it from the list and insert it at the start. Simplicity.
This is probably more than you need.
Need help with some basic thinking in Java, I've got a working program but I feel that the structure is wrong.
You can give the program a zip file, it will extract it and then delete all empty files and all subfolders that have empty files. So basically when it's unzipped there can be X amount of folders, and those folders can have X amount of folders (and it's likely that those folders also have subfolders, this can go on). The application needs to check each subfolder until there are no more folders, delete all empty files and if the folder is empty, delete the folder aswell.
what would be a good way to implement this? A method that checks the mainfolder, and if there are directories in that folder, send it to another method that will clean the folder and check for more subfolders? The main problem is how I can check all folders without knowing the amounts of folders and subfolders.
[QUOTE=Cuel;34603694]Need help with some basic thinking in Java, I've got a working program but I feel that the structure is wrong.
You can give the program a zip file, it will extract it and then delete all empty files and all subfolders that have empty files. So basically when it's unzipped there can be X amount of folders, and those folders can have X amount of folders (and it's likely that those folders also have subfolders, this can go on). The application needs to check each subfolder until there are no more folders, delete all empty files and if the folder is empty, delete the folder aswell.
what would be a good way to implement this? A method that checks the mainfolder, and if there are directories in that folder, send it to another method that will clean the folder and check for more subfolders? The main problem is how I can check all folders without knowing the amounts of folders and subfolders.[/QUOTE]
Recursion.
Thanks bby.
[editline]8th February 2012[/editline]
[url]http://pastebin.com/Kg7FNP5S[/url]
good/bad?
[del]What would be a good way to delete the folders if they are empty after deleting the files?[/del] - solved, added
[code]
if (file.isDirectory() && file != this.getDefaultDirectory()) {
File[] itemsInFolder = file.listFiles();
System.out.println(itemsInFolder.length);
if (itemsInFolder.length == 0){
file.delete();
}
}[/code]
at the bottom.
anything else for error handling etc?
[QUOTE=kaukassus;34603362] ... [/QUOTE]
I just did something similar last night and this is what I did..
[lua]
//Define event in your class
public delegate void Connect(object sender, EventArgs args);
public event Connect OnConnect;
void CallEvent() {
if(this.OnConnect)
this.OnConnect(this, Eventargs.Empty);
}
[/lua]
[url='http://www.facepunch.com/threads/1162206']Need help creating flags on sounds and creating them without header.[/url]
I need to write a simple program (because I don't know of one that exists) that allows me to create a tree of objects.
>node1
>>sub node1
>>>subsub node1
>>>subsub node2
>>>subsub node3
>>sub node2
>>sub node3
>>sub node4
>node2
I was thinking of writing it in visual basic (which I have forgotten) but perhaps there is something better to use.
I'd go about HTML5 but I'm not sure how much data can be stored from a browser.
I need this to write out ideas for my story. Superficial scope nodes are for general events that I need to detail later with deeper scope nodes.
OH .... Silver Light?
Working with WebGL using JavaScript and I've run into the weirdest error ever. I have this part:
[code]
flatShader.VertexPositionAttribute = gl.getAttribLocation( flatShader, "v3VertexPosition" );
gl.enableVertexAttribArray( flatShader.VertexPositionAttribute );
[/code]
This works, no problems at all and the shader is used to draw some lines etc...
However:
[code]
textureShader.VertexPositionAttribute = gl.getAttribLocation( textureShader, "a_v3VertexPosition" );
gl.enableVertexAttribArray( textureShader.VertexPositionAttribute );
[/code]
The next piece of code only works if I comment out the gl.enableVertexAttribArray line, otherwise an error 1282 ( INVALID_OPERATION ) occurs.
[code]
gl.useProgram( flatShader );
gl.bindBuffer( gl.ARRAY_BUFFER, buffer );
gl.vertexAttribPointer( flatShader.VertexPositionAttribute, 3, gl.FLOAT, false, 0, 0 );
gl.uniformMatrix4fv( flatShader.mvpMatrixUniform, false, mvpMatrix );
gl.drawArrays( gl.LINES, 0, 2 );
gl.bindBuffer( gl.ARRAY_BUFFER, null );
gl.useProgram( null );
[/code]
More specifically, gl.drawArrays errors out with that error. HOWEVER, the following does not generate the same error:
[code]
textureShader.TextureCoordAttribute = gl.getAttribLocation( textureShader, "a_v2TextureCoord" );
gl.enableVertexAttribArray( textureShader.TextureCoordAttribute );
[/code]
So what the fuck is wrong with the VertexPosition variable!? I have checked, doublechecked and rechecked every single line and there is not a single mistype to spot. And it works as soon as I comment out that line. If I add a deliberate type error in there, such as:
[code]
textureShader.VertexPositionAttribute = gl.getAttribLocation( textureShader, "a_v3VertexPosition" );
gl.enableVertexAttribArray( textureShader.NOSUCHVARIABLE )
[/code]
It keeps on going happily and enableVertex errors out with a INVALID_VALUE instead, however the lines are drawn.
Why the fuck does that one line make glDrawArrays error out, when the next glEnableVertexAttribArray does not!?
[B]EDIT[/B]
Figured out what was wrong. I was enabling the vertexarrays too early and unlike OpenGL, WebGL will error out on glDrawArrays / glDrawElements calls if a vertexarray is enabled on a buffer that is not populated. However after I fixed this, I still haven't been able to get my textured quad working yet... Would anybody care taking a look at my code and see if they can spot any issues that I might have missed?
[url]http://dl.dropbox.com/u/40398697/WebGLProject/WebGLProject.rar[/url]
Any help is appreciated. :)
Could anybody take a look at this : [url]http://gamedev.stackexchange.com/questions/23549/trace-with-2d-terrain[/url]
@capsup:
Just out of curiosity, does it work if you replace gl.drawArrays with gl.drawElements, with an index buffer containing just "1, 2, 3, 4, 5, ..., n-1, n"?
[QUOTE=quincy18;34607733]Could anybody take a look at this : [url]http://gamedev.stackexchange.com/questions/23549/trace-with-2d-terrain[/url][/QUOTE]
If you are seeing if a line intersects with another line, I'd use this article: [url]http://paulbourke.net/geometry/lineline2d/[/url]
[QUOTE=sim642;34602825]A hacky way to do it would be to render the text into sf::RenderTexture and then render that onto you sf::RenderWindow.[/QUOTE]
That's what I was hoping to not do, but it seems like my only option.
[QUOTE=quincy18;34607733]Could anybody take a look at this : [url]http://gamedev.stackexchange.com/questions/23549/trace-with-2d-terrain[/url][/QUOTE]
To find which cell in the terrain to intersect with, think of it top-down as drawing a line in 2D.
I'm going to use 'x[sub]0[/sub]' and 'x[sub]1[/sub]' to denote the minimum and maximum x-values of the current cell, respectively (same goes for y[sub]0[/sub], y[sub]1[/sub]). Likewise, z[sub]00[/sub] is going to denote corner with x=x[sub]0[/sub] and y=y[sub]0[/sub].
Also, I'm going to use values <dx, dy, dz>, which represent the direction of the trace (they do not need to be normalized), and <x[sub]initial[/sub], y[sub]initial[/sub], z[sub]initial[/sub]> as the start of the trace.
Start at the trace position, iterate by:
x[sub]t[/sub] = dx < 0.0 ? x[sub]0[/sub] - x : x[sub]1[/sub] - x
y[sub]t[/sub] = dy < 0.0 ? y[sub]0[/sub] - x : y[sub]1[/sub] - y
t[sub]x[/sub] = x[sub]t[/sub] / dx;
t[sub]y[/sub] = y[sub]t[/sub] / dy;
t[sub]0[/sub] = (t[sub]x[/sub] < t[sub]y[/sub] ? t[sub]x[/sub] : t[sub]y[/sub]) + epsilon
x += dx * t[sub]0[/sub];
y += dy * t[sub]0[/sub];
z += dz * t[sub]0[/sub];
Now you have the current position (at the edge of the next nearest cell).
Long story short, trying to solve from bilinear interpolation doesn't work out well. (The equation was like a full page).
Instead, I'm going to define the surface of the polygon by its approximate partial-derivatives:
z[sub]y[/sub] = (z[sub]1[/sub] - z[sub]0[/sub]) / (y[sub]1[/sub] - y[sub]0[/sub])
z[sub]x[/sub] = (z[sub]1[/sub] - z[sub]0[/sub]) / (x[sub]1[/sub] - x[sub]0[/sub])
So that:
z = z[sub]y[/sub] * (y - y[sub]0[/sub]) + z[sub]x[/sub] * (x - x[sub]0[/sub]) + z[sub]00[/sub]
The line is defined by:
x = dx * t + x[sub]initial[/sub],
y = dy * t + y[sub]initial[/sub],
z = dz * t + z[sub]initial[/sub],
Substituting the line equations back in:
dz * t + z[sub]initial[/sub] = z[sub]y[/sub] * (dy * t + y[sub]initial[/sub] - y[sub]0[/sub]) + z[sub]x[/sub] * (dx * t + x[sub]initial[/sub] - x[sub]0[/sub]) + z[sub]00[/sub]
Solving for t:
t = (z[sub]y[/sub] * (y[sub]initial[/sub] - y[sub]0[/sub]) + z[sub]x[/sub] (x[sub]initial[/sub] - x[sub]0[/sub]) + z[sub]00[/sub] - z[sub]initial[/sub]) / (dz + dy * z[sub]y[/sub] + dx * z[sub]x[/sub])
Substitute the value of t back into the line equation to get a point of intersection, check that point against the x- and y- bounds of the current cell.
And oh dear god I hope that's right. I wrote it all off the top of my head, so verify the crap out of it.
EFFFFFFFFFFFFFFFFFFFff. [b]2D[/b] terrain. Blargl.
Can someone help me with why this isn't working? (programming in C)
[code]#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
char rot13char(char c)
{
if(!isalpha(c))
{
return c;
}
else if(islower(c))
{
if(c > 'n')
{
return c -= 13;
}
else
{
return c += 13;
}
}
else
{
if(c > 'N')
{
return c -= 13;
}
else
{
return c += 13;
}
}
}
void rot13str(char str[])
{
int i;
for(i=0; i != EOF; i++)
{
char c = getchar();
str[i] = rot13char(c);
}
}
int main(void)
{
64 char *s;
char c[101];
s = fgets(c, 101, stdin);
printf("Enter lines: ");
71 while(s != EOF)
{
printf("%s", c);
s = fgets(c, 101, stdin);
}
return 0;
}[/code]
The purpose of the program is to take user input as a string, then convert the string by rot13 (a to n, b to o, c to p, etc.) and print it out. When compiling I receive the following errors:
64: ISO C90 forbids mixed declarations and code
71: comparison between pointer and integer
I put 64 and 71 in the code to make it easier to find them. I'm not really sure how to fix these or why they're coming up.
[QUOTE=DSG;34614676]Can someone help me with why this isn't working? (programming in C)
[code]#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
char rot13char(char c)
{
if(!isalpha(c))
{
return c;
}
else if(islower(c))
{
if(c > 'n')
{
return c -= 13;
}
else
{
return c += 13;
}
}
else
{
if(c > 'N')
{
return c -= 13;
}
else
{
return c += 13;
}
}
}
void rot13str(char str[])
{
int i;
for(i=0; i != EOF; i++)
{
char c = getchar();
str[i] = rot13char(c);
}
}
int main(void)
{
64 char *s;
char c[101];
s = fgets(c, 101, stdin);
printf("Enter lines: ");
71 while(s != EOF)
{
printf("%s", c);
s = fgets(c, 101, stdin);
}
return 0;
}[/code]
The purpose of the program is to take user input as a string, then convert the string by rot13 (a to n, b to o, c to p, etc.) and print it out. When compiling I receive the following errors:
64: ISO C90 forbids mixed declarations and code
71: comparison between pointer and integer
I put 64 and 71 in the code to make it easier to find them. I'm not really sure how to fix these or why they're coming up.[/QUOTE]
It should be
[code]while (*s != EOF)
or
while (s != NULL)[/code]
fgets returns a pointer to whatever is read. Also, in this case you are better off just using gets(), which automatically reads from stdin. I'm not sure why you're reading into two different strings at this point, just read into c or something.
I need help deciding what scripting language to use for my Qt application. I want to give users the ability to write plugins. Similar to [URL="http://sublimetext.info/docs/en/extensibility/plugins.html"]Sublime Text 2[/URL].
[URL="http://developer.qt.nokia.com/doc/qt-4.8/qtscript.html"]QtScript [/URL]and [URL="http://www.nongnu.org/libqtlua/"]QtLua[/URL] looks like two solutions. I prefer Lua, but it looks like QtScript is easier to integrate with existing QObject classes.
Have anyone used either of these libraries? If so, what was your experience with it?
Don't use gets or fgets.
I'm in a bit of of what is medically known as a pickle. I'm making a small screen with a panel that takes a color and paints to a panel when the mouse is clicked and dragged. Problem is, I've hit a metaphorical wall, I don't really know how to get this done. How?
Java btw.
Oh, and here comes the wall of probably incredibly painful to look at code, ye be warned.
[code]package swing2;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LayoutStuff extends JFrame implements AdjustmentListener,MouseListener
{
JPanel east = new JPanel();
JPanel bottom = new JPanel();
JPanel palette = new JPanel();
JButton button1 = new JButton("Red");
JButton button2 = new JButton("Blue");
JButton button3 = new JButton("Green");
JButton button4 = new JButton("Black");
JButton button5 = new JButton("Erase");
JScrollBar scrollbar1 = new JScrollBar (JScrollBar.HORIZONTAL, 0, 10, 0, 255);
JScrollBar scrollbar2 = new JScrollBar (JScrollBar.HORIZONTAL, 0, 10, 0, 255);
JScrollBar scrollbar3 = new JScrollBar (JScrollBar.HORIZONTAL, 0, 10, 0, 255);
MyWindowListener myWindowListener;
JbuttonListener JbuttonListener;
int muisx;
int muisy;
PaintingStuff pstuff = new PaintingStuff();
LayoutStuff()
{
setupUI();
}
private void setupUI()
{
myWindowListener = new MyWindowListener();
addWindowListener(myWindowListener);
Container c = getContentPane();
c.setLayout(new BorderLayout());
east.setLayout(new GridLayout(6,1));
button1.setBackground(Color.RED);
button2.setBackground(Color.BLUE);
button3.setBackground(Color.GREEN);
button4.setBackground(Color.BLACK);
palette.setBackground(Color.BLACK);
scrollbar1.setBackground(Color.RED);
scrollbar2.setBackground(Color.GREEN);
scrollbar3.setBackground(Color.BLUE);
scrollbar1.addAdjustmentListener(this);
scrollbar2.addAdjustmentListener(this);
scrollbar3.addAdjustmentListener(this);
east.add(button1);
east.add(button2);
east.add(button3);
east.add(button4);
east.add(button5);
east.add(palette);
JbuttonListener = new JbuttonListener();
button1.addActionListener(JbuttonListener);
button2.addActionListener(JbuttonListener);
button3.addActionListener(JbuttonListener);
button4.addActionListener(JbuttonListener);
button5.addActionListener(JbuttonListener);
bottom.setLayout(new GridLayout(3,1));
bottom.add(scrollbar1);
bottom.add(scrollbar2);
bottom.add(scrollbar3);
pstuff.setBackground(Color.WHITE);
c.addMouseListener(this);
c.add(pstuff);
c.add(BorderLayout.EAST, east);
c.add(BorderLayout.SOUTH, bottom);
setSize(500,500);
setVisible(true);
}
public static void main(String[] args) {
LayoutStuff layout = new LayoutStuff();
}
class JbuttonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("Red"))
{
palette.setBackground(Color.RED);
}
else
if (e.getActionCommand().equals("Blue"))
{
palette.setBackground(Color.BLUE);
}
else
if(e.getActionCommand().equals("Green"))
{
palette.setBackground(Color.GREEN);
}
else
if(e.getActionCommand().equals("Black"))
{
palette.setBackground(Color.BLACK);
}
else
if(e.getActionCommand().equals("Erase"))
{
palette.setBackground(Color.BLACK);
palette.repaint();
scrollbar1.setValue(0);
scrollbar2.setValue(0);
scrollbar3.setValue(0);
}
}
}
public void adjustmentValueChanged(AdjustmentEvent evt)
{
int r = scrollbar1.getValue();
int g = scrollbar2.getValue();
int b = scrollbar3.getValue();
palette.setBackground(new Color(r,g,b));
palette.repaint();
}
public void drawPixel (Graphics g, int muisx, int muisy)
{
g.fillRect(muisx,muisy,1,1);
}
public void mouseDragged(MouseEvent e)
{
}
public void mousePressed(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
muisx = e.getX();
muisy = e.getY();
System.out.println(muisx + "," + muisy);
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
}[/code]
So how do i detect collisions between a Vector3 value and a huge (huge as in a list that could contain way over 15,000 vertices) list of vertices in XNA?
Also, how do i draw 2D lines in XNA as well?
[editline]lolasd[/editline]
Man this thread is slow.
[QUOTE=Octave;34616798]It should be
[code]while (*s != EOF)
or
while (s != NULL)[/code]
fgets returns a pointer to whatever is read. Also, in this case you are better off just using gets(), which automatically reads from stdin. I'm not sure why you're reading into two different strings at this point, just read into c or something.[/QUOTE]
I'm in the process of learning C and I'm taking a class for it but when it comes to specific things like this we don't really go over these things. :\ Also I tried changing it to while (*s != EOF) and I still get the error on line 64 for "ISO C90 forbids mixed declarations and code."
[QUOTE=Jookia;34617069]Don't use gets or fgets.[/QUOTE]
Why not?
[QUOTE=DSG;34621865]Why not?[/QUOTE]
Buffer overflow. Someone gives you more data than you asked for and suddenly your program segfaults or has a potential exploit vector.
[QUOTE=esalaka;34622123]Buffer overflow. Someone gives you more data than you asked for and suddenly your program segfaults or has a potential exploit vector.[/QUOTE]
As an alternative, getline() works fine if you have glibc.
[editline]9th February 2012[/editline]
Also, "ISO C90 forbids mixed declarations and code." has to do with your compiler, what command/options are you compiling with? The results from searching this error told me that in K&R's original C standard, declarations can only be at the start of blocks. But in your case, both of your string declarations [i]are[/i] right after the beginning of the main function's block, so I don't know. Maybe try changing your compiler settings if you can.
Yeah, which compiler are you using DSG? It compiles fine for me using GCC v.4.6.2.
EDIT: can you upload the actual file somewhere? It might be some weird encoding/line ending problem.
-ansi -Wall -pedantic are my required compiling commands, and it's C90, not C99, and I'm doing it in CodeBlocks. However, even when I try compiling with std=c99 instead of -ansi (which is C90) it'll compile, but not run properly at all. I'll just get a blank terminal window that doesn't print anything and doesn't seem to take any input or output anything as a result.
Also, my teacher told us to use fgets for strings so I don't know what to really say to that one about the buffer overflow thing. What would I use instead otherwise?
Sorry, you need to Log In to post a reply to this thread.